Challenge - 5 Problems
Image View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
Displaying a system image in SwiftUI
What will be displayed by this SwiftUI code snippet?
iOS Swift
import SwiftUI struct ContentView: View { var body: some View { Image(systemName: "star.fill") .foregroundColor(.yellow) .font(.largeTitle) } }
Attempts:
2 left
💡 Hint
The systemName parameter uses SF Symbols, and foregroundColor changes the icon color.
✗ Incorrect
The code uses Image(systemName:) to show the SF Symbol "star.fill" which is a filled star. The foregroundColor(.yellow) changes the star's color to yellow, and font(.largeTitle) makes it large.
❓ ui_behavior
intermediate1:30remaining
Displaying an asset image in UIKit
What will this UIKit code display on the screen?
iOS Swift
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let imageView = UIImageView(image: UIImage(named: "logo")) imageView.frame = CGRect(x: 50, y: 50, width: 100, height: 100) view.addSubview(imageView) } }
Attempts:
2 left
💡 Hint
UIImage(named:) loads images from the app's asset catalog by name.
✗ Incorrect
UIImage(named: "logo") loads the image named "logo" from the app's assets. UIImageView displays it at the specified frame. This code shows the image at (50,50) with width and height 100.
📝 Syntax
advanced1:30remaining
Correct syntax for system image with rendering mode
Which option correctly creates a SwiftUI Image with system name "heart" and applies original rendering mode?
Attempts:
2 left
💡 Hint
Rendering mode is a modifier method in SwiftUI, not a parameter in initializer.
✗ Incorrect
In SwiftUI, renderingMode is a modifier method called on the Image view. Option A uses the correct syntax. Option A tries to pass renderingMode as a parameter which is invalid. Option A uses .template which is different mode. Option A uses wrong method name.
🔧 Debug
advanced1:30remaining
Why does UIImage(named:) return nil?
Given this UIKit code, why might imageView.image be nil?
let imageView = UIImageView()
imageView.image = UIImage(named: "icon")
Attempts:
2 left
💡 Hint
UIImage(named:) returns nil if the image name is not found in assets or bundle.
✗ Incorrect
UIImage(named:) looks for the image in the app's asset catalog or bundle by name. If the image is missing or the name is misspelled, it returns nil. UIImageView can display images loaded this way. The method does not require full path. Setting image outside viewDidLoad is allowed.
🧠 Conceptual
expert2:00remaining
Difference between system and asset images in iOS
Which statement correctly describes the difference between system images and asset images in iOS development?
Attempts:
2 left
💡 Hint
Think about where system images come from and how asset images are added.
✗ Incorrect
System images are vector icons called SF Symbols provided by Apple and can be used by name. Asset images are custom images developers add to the app's asset catalog or bundle. System images are vector and scalable, asset images can be raster or vector. Both UIKit and SwiftUI can use both types.