Challenge - 5 Problems
GeometryReader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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)
}Attempts:
2 left
💡 Hint
Remember geometry.size gives the full size of the parent container.
✗ Incorrect
The GeometryReader provides the full size (300x300). Dividing by 2 results in 150x150 for the red square.
🧠 Conceptual
intermediate1:30remaining
Why use GeometryReader in SwiftUI layouts?
What is the main purpose of using GeometryReader in SwiftUI?
Attempts:
2 left
💡 Hint
Think about how you can make views adjust to different screen sizes.
✗ Incorrect
GeometryReader lets you read the size and position of the container, so you can adapt your layout accordingly.
📝 Syntax
advanced2: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)")
}Attempts:
2 left
💡 Hint
Check if the closure syntax is correct with 'in' keyword.
✗ Incorrect
Option C is missing the 'in' keyword after the closure parameter, causing a syntax error.
❓ lifecycle
advanced1:30remaining
When does GeometryReader update its size information?
At what point does GeometryReader provide updated size information to its content closure?
Attempts:
2 left
💡 Hint
Think about adaptive layouts reacting to screen rotations or resizing.
✗ Incorrect
GeometryReader updates its geometry values whenever the parent view changes size or position, enabling dynamic layouts.
🔧 Debug
expert2: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)
}
}Attempts:
2 left
💡 Hint
Think about how flexible views inside stacks behave with GeometryReader sizes.
✗ Incorrect
Color.blue tries to fill the entire GeometryReader size inside a VStack, which causes the VStack to expand infinitely because it has no fixed size constraints.