0
0
iOS Swiftmobile~20 mins

Modifier chaining in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What color will the text be?
Consider this SwiftUI code that chains modifiers on a Text view. What color will the text appear as on screen?
iOS Swift
Text("Hello World")
  .foregroundColor(.red)
  .foregroundColor(.blue)
ABlack
BRed
CPurple
DBlue
Attempts:
2 left
💡 Hint
Think about the order of modifiers and which one applies last.
📝 Syntax
intermediate
2:00remaining
Which modifier chain compiles without error?
Which of these SwiftUI modifier chains is syntactically correct?
AText("Hi").padding().background(Color.red).font(.title)
BText("Hi").padding().background(Color.red).font.title()
CText("Hi").padding.background(Color.red).font(.title)
DText("Hi").padding().background(Color.red).font
Attempts:
2 left
💡 Hint
Check if each modifier is called as a function with parentheses.
lifecycle
advanced
2:00remaining
What happens if you chain .onAppear twice?
Given this SwiftUI code, what will happen when the view appears?
iOS Swift
Text("Welcome")
  .onAppear { print("First") }
  .onAppear { print("Second") }
ABoth "First" and "Second" are printed
BNo output is printed
COnly "Second" is printed
DOnly "First" is printed
Attempts:
2 left
💡 Hint
Think about whether modifiers replace or add behavior.
navigation
advanced
2:00remaining
Which modifier chain correctly adds a navigation title and a button?
Which SwiftUI modifier chain correctly adds a navigation title and a trailing button to a view?
A
Text("Home")
  .navigationTitle("Main")
  .toolbar { Button("Edit") {} }
B
Text("Home")
  .toolbar { Button("Edit") {} }
  .navigationTitle("Main")
C
Text("Home")
  .navigationTitle("Main", displayMode: .inline)
  .toolbar { Button("Edit") {} }
D
Text("Home")
  .toolbar { Button("Edit") {} }
  .navigationBarTitle("Main")
Attempts:
2 left
💡 Hint
Check the correct modifier names and their order.
🔧 Debug
expert
2:00remaining
Why does this modifier chain cause a runtime crash?
Examine this SwiftUI code. Why does it crash at runtime?
iOS Swift
Text("Crash")
  .frame(width: 100, height: 50)
  .background(Color.red)
  .clipShape(Circle())
Aframe modifier requires explicit alignment parameter to avoid crash
BclipShape(Circle()) clips the rectangular frame causing layout conflict
Cbackground(Color.red) must come after clipShape to avoid crash
DText view cannot be clipped with clipShape
Attempts:
2 left
💡 Hint
Think about shape clipping on rectangular frames.