Bird
0
0

Which of the following is the correct syntax to chain modifiers on a Text view in SwiftUI?

easy📝 Syntax Q12 of 15
iOS Swift - SwiftUI Basics
Which of the following is the correct syntax to chain modifiers on a Text view in SwiftUI?
AText("Hi").font(.title).foregroundColor(.red)
BText("Hi") font(.title) foregroundColor(.red)
CText("Hi").font = .title.foregroundColor = .red
DText("Hi").font(.title), foregroundColor(.red)
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct chaining syntax

    In SwiftUI, modifiers are chained by calling them one after another with dots, like .font() then .foregroundColor().
  2. Step 2: Check each option

    Text("Hi").font(.title).foregroundColor(.red) correctly chains modifiers with dots. Others miss dots or use invalid syntax.
  3. Final Answer:

    Text("Hi").font(.title).foregroundColor(.red) -> Option A
  4. Quick Check:

    Correct chaining uses dots between modifiers [OK]
Quick Trick: Use dot before each modifier to chain [OK]
Common Mistakes:
  • Omitting dots between modifiers
  • Using assignment (=) instead of method calls
  • Separating modifiers with commas

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes