Build: Simple Greeting Screen
This screen shows a greeting message using a SwiftUI View that conforms to the View protocol and implements the body property.
Target UI
--------------------- | | | Hello, Friend! | | | ---------------------
--------------------- | | | Hello, Friend! | | | ---------------------
import SwiftUI
struct GreetingView: View {
// TODO: Implement the body property here
}
struct GreetingView_Previews: PreviewProvider {
static var previews: some View {
GreetingView()
}
}import SwiftUI struct GreetingView: View { var body: some View { VStack { Spacer() Text("Hello, Friend!") .font(.title) .multilineTextAlignment(.center) Spacer() } } } struct GreetingView_Previews: PreviewProvider { static var previews: some View { GreetingView() } }
We created a struct GreetingView that conforms to the View protocol. This requires a body property that returns some View.
Inside body, we used a VStack with Spacer() above and below the Text to center it vertically.
The Text displays the greeting message. We set the font to .title for better visibility and aligned the text to center horizontally.
This simple structure demonstrates how to implement the View protocol and provide the required body property.
--------------------- | | | Hello, Friend! | | | ---------------------
body property in a SwiftUI View protocol represent?body property in a SwiftUI View?struct ContentView: View {
var body: some View {
VStack {
Text("Hello")
Text("World")
}
}
}struct MyView: View {
var body: View {
Text("Hi")
}
}body implementation correctly achieves this?Pass the test and this pattern moves unknown