Challenge - 5 Problems
Swift Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate1:30remaining
Swift Data Type Declaration
What is the output of this Swift code snippet?
iOS Swift
let number: Int = 10 let price: Double = 9.99 let name: String = "Coffee" let isAvailable: Bool = true print("\(name) costs \(price) and availability is \(isAvailable)")
Attempts:
2 left
💡 Hint
Remember how Swift prints Boolean values in strings.
✗ Incorrect
In Swift, Bool values print as 'true' or 'false' in lowercase when interpolated in strings.
❓ ui_behavior
intermediate1:30remaining
Displaying Different Data Types in UILabel
You want to show an integer, a double, and a boolean in a UILabel in Swift. Which code snippet correctly converts all values to a string for display?
Attempts:
2 left
💡 Hint
You cannot add non-string types directly to strings in Swift.
✗ Incorrect
In Swift, you must convert non-string types to String before concatenation with + operator. String interpolation (option A) also works but option A explicitly converts each value.
🧠 Conceptual
advanced1:30remaining
Type Safety in Swift
Which statement best describes Swift's type safety with Int, Double, String, and Bool?
Attempts:
2 left
💡 Hint
Think about how Swift handles different numeric types.
✗ Incorrect
Swift is strongly typed and does not allow implicit conversion between Int and Double. You must convert explicitly using initializers like Double(intValue).
❓ lifecycle
advanced1:30remaining
Variable Initialization and Default Values
What is the default value of an uninitialized variable of type Bool in Swift?
Attempts:
2 left
💡 Hint
Swift enforces initialization before use.
✗ Incorrect
Swift requires all variables to be initialized before use. Declaring a variable without initialization causes a compile-time error.
🔧 Debug
expert2:00remaining
Debugging Type Mismatch Error
What error will this Swift code produce?
let value: Int = 5
let result: Double = value
print(result)
iOS Swift
let value: Int = 5 let result: Double = value print(result)
Attempts:
2 left
💡 Hint
Check how Swift handles assigning Int to Double variables.
✗ Incorrect
Swift does not implicitly convert Int to Double. You must explicitly convert using Double(value).