Bird
0
0

Identify the error in this SwiftUI code snippet:

medium📝 Debug Q6 of 15
iOS Swift - SwiftUI Basics
Identify the error in this SwiftUI code snippet:
Text("Hello")
  .foregroundcolor(.green)
AText view cannot have modifiers
BIncorrect capitalization of the modifier name
CInvalid color value
DMissing parentheses after Text
Step-by-Step Solution
Solution:
  1. Step 1: Check modifier spelling and capitalization

    The correct modifier is foregroundColor with a capital 'C'. The code uses foregroundcolor which is incorrect.
  2. Step 2: Verify other parts

    Parentheses after Text are correct, color value is valid, and Text views can have modifiers.
  3. Final Answer:

    Incorrect capitalization of the modifier name -> Option B
  4. Quick Check:

    Modifier names are case-sensitive = D [OK]
Quick Trick: Modifier names are case-sensitive; watch capitalization [OK]
Common Mistakes:
  • Using lowercase 'c' in foregroundColor
  • Assuming modifiers are case-insensitive
  • Thinking Text cannot have modifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes