0
0
iOS Swiftmobile~20 mins

GeometryReader for adaptive layouts in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GeometryReader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the size of the red square inside GeometryReader?
Given this SwiftUI code, what size will the red square have when the parent view is 300x300 points?
iOS Swift
GeometryReader { geometry in
  Color.red
    .frame(width: geometry.size.width / 2, height: geometry.size.height / 2)
}
A150x150 points
B300x300 points
C75x75 points
D100x100 points
Attempts:
2 left
💡 Hint
Remember geometry.size gives the full size of the parent container.
🧠 Conceptual
intermediate
1:30remaining
Why use GeometryReader in SwiftUI layouts?
What is the main purpose of using GeometryReader in SwiftUI?
ATo handle user input events
BTo create animations easily
CTo load images asynchronously
DTo get the size and position of the parent view for adaptive layouts
Attempts:
2 left
💡 Hint
Think about how you can make views adjust to different screen sizes.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GeometryReader usage
Which option contains a syntax error in using GeometryReader?
iOS Swift
GeometryReader { geometry in
  Text("Width: \(geometry.size.width)")
}
A
GeometryReader { geometry in
  Text("Width: \(geometry.size.width)")
}
BGeometryReader { geometry in Text("Width: \(geometry.size.width)") }
CGeometryReader { geometry Text("Width: \(geometry.size.width)") }
D
}
)")htdiw.ezis.yrtemoeg(\ :htdiW"(txeT  
ni yrtemoeg { redaeRyrtemoeG
Attempts:
2 left
💡 Hint
Check if the closure syntax is correct with 'in' keyword.
lifecycle
advanced
1:30remaining
When does GeometryReader update its size information?
At what point does GeometryReader provide updated size information to its content closure?
AWhenever the parent view’s size or position changes
BOnly once when the view is created
CWhen the user taps the view
DOnly when the app launches
Attempts:
2 left
💡 Hint
Think about adaptive layouts reacting to screen rotations or resizing.
🔧 Debug
expert
2:30remaining
Why does this GeometryReader cause layout issues?
This code causes the view to expand infinitely and crash. Why? GeometryReader { geometry in VStack { Text("Hello") Color.blue.frame(width: geometry.size.width, height: geometry.size.height) } }
iOS Swift
GeometryReader { geometry in
  VStack {
    Text("Hello")
    Color.blue.frame(width: geometry.size.width, height: geometry.size.height)
  }
}
ABecause Text("Hello") is missing a frame modifier
BBecause Color.blue inside VStack tries to fill all space, causing infinite size conflict
CBecause GeometryReader cannot be used inside VStack
DBecause the frame width and height are set to zero
Attempts:
2 left
💡 Hint
Think about how flexible views inside stacks behave with GeometryReader sizes.