0
0
iOS Swiftmobile~20 mins

Data types (Int, Double, String, Bool) in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift Data Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1: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)")
ACoffee costs 9.99 and availability is True
BCoffee costs 9.99 and availability is 1
CCoffee costs 9.99 and availability is true
DCoffee costs 9.99 and availability is Yes
Attempts:
2 left
💡 Hint
Remember how Swift prints Boolean values in strings.
ui_behavior
intermediate
1: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?
Alabel.text = "Int: " + String(intValue) + ", Double: " + String(doubleValue) + ", Bool: " + String(boolValue)
Blabel.text = String(intValue) + String(doubleValue) + String(boolValue)
Clabel.text = "Int: \(intValue), Double: \(doubleValue), Bool: \(boolValue)"
Dlabel.text = "Int: " + intValue + ", Double: " + doubleValue + ", Bool: " + boolValue
Attempts:
2 left
💡 Hint
You cannot add non-string types directly to strings in Swift.
🧠 Conceptual
advanced
1:30remaining
Type Safety in Swift
Which statement best describes Swift's type safety with Int, Double, String, and Bool?
ASwift automatically converts String to Int if the string contains digits.
BSwift requires explicit conversion between Int and Double to avoid type errors.
CSwift treats Bool as a subtype of Int, so they can be used interchangeably.
DSwift allows implicit conversion between Int and Double without errors.
Attempts:
2 left
💡 Hint
Think about how Swift handles different numeric types.
lifecycle
advanced
1:30remaining
Variable Initialization and Default Values
What is the default value of an uninitialized variable of type Bool in Swift?
Atrue
Bfalse
Cnil
DSwift does not allow uninitialized variables; it causes a compile error
Attempts:
2 left
💡 Hint
Swift enforces initialization before use.
🔧 Debug
expert
2: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)
AType mismatch error: Cannot assign Int to Double without conversion
BPrints 5.0 without error
CRuntime error: Cannot convert Int to Double
DSyntax error: Missing semicolon
Attempts:
2 left
💡 Hint
Check how Swift handles assigning Int to Double variables.