Bird
0
0

Identify the error in this SwiftUI view code:

medium📝 Debug Q14 of 15
iOS Swift - SwiftUI Basics
Identify the error in this SwiftUI view code:
struct MyView: View {
  var body: View {
    Text("Hi")
  }
}
Abody must return 'some View', not 'View'
BText cannot be used inside body
CMissing parentheses after Text("Hi")
Dbody must be a function, not a property
Step-by-Step Solution
Solution:
  1. Step 1: Check the body property type

    The body property must return 'some View' to satisfy the View protocol.
  2. Step 2: Identify the incorrect return type

    The code uses 'View' instead of 'some View', which causes a compile error.
  3. Final Answer:

    body must return 'some View', not 'View' -> Option A
  4. Quick Check:

    body return type = some View [OK]
Quick Trick: Always use 'some View' as body return type [OK]
Common Mistakes:
  • Using 'View' instead of 'some View'
  • Thinking Text needs parentheses
  • Confusing property with function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes