Bird
0
0

Which of the following is the correct way to declare the body property in a SwiftUI View?

easy📝 Syntax Q12 of 15
iOS Swift - SwiftUI Basics
Which of the following is the correct way to declare the body property in a SwiftUI View?
Avar body: some View { Text("Hello") }
Bfunc body() -> View { Text("Hello") }
Clet body = Text("Hello")
Dvar body: View { return "Hello" }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the View protocol requirement

    The body property must be a computed property returning some View.
  2. Step 2: Check each option's syntax

    var body: some View { Text("Hello") } correctly declares a computed property with type some View returning a Text view.
  3. Final Answer:

    var body: some View { Text("Hello") } -> Option A
  4. Quick Check:

    body is a computed property returning some View [OK]
Quick Trick: body is always a computed property returning some View [OK]
Common Mistakes:
  • Using func instead of var for body
  • Returning a String instead of a View
  • Declaring body as a stored property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes