Bird
0
0

Identify the error in this SwiftUI modifier chain:

medium📝 Debug Q14 of 15
iOS Swift - SwiftUI Basics
Identify the error in this SwiftUI modifier chain:
Text("Welcome")
  .font(.headline)
  .padding
  .background(Color.yellow)
ACannot chain .background after .padding
BIncorrect order of modifiers
CMissing parentheses after .padding
DText view cannot have .font modifier
Step-by-Step Solution
Solution:
  1. Step 1: Check each modifier syntax

    Modifiers like .padding require parentheses even if no parameters are passed.
  2. Step 2: Locate the error

    Here, .padding is missing parentheses, causing a syntax error.
  3. Final Answer:

    Missing parentheses after .padding -> Option C
  4. Quick Check:

    Modifiers need parentheses even if empty [OK]
Quick Trick: Always add () after modifiers like .padding [OK]
Common Mistakes:
  • Omitting parentheses on parameterless modifiers
  • Thinking order of modifiers causes error here
  • Believing .background can't follow .padding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes