An Int is a data type that stores whole numbers without decimals, like 5 or -10.
Click to reveal answer
beginner
How does Double differ from Int?
Double stores numbers with decimals, like 3.14, while Int stores whole numbers only.
Click to reveal answer
beginner
What kind of values does Bool hold?
Bool holds only two values: true or false. It is used for yes/no or on/off decisions.
Click to reveal answer
beginner
What is a String in Swift?
String is a data type that stores text, like words or sentences, for example: "Hello" or "Swift".
Click to reveal answer
intermediate
Why is it important to use the correct data type in Swift?
Using the correct data type helps the app use memory efficiently and prevents errors by making sure data is handled properly.
Click to reveal answer
Which Swift data type would you use to store the number 42?
ABool
BInt
CString
DDouble
✗ Incorrect
42 is a whole number, so Int is the correct data type.
Which data type can hold the value 3.14159?
ADouble
BInt
CBool
DString
✗ Incorrect
Double stores decimal numbers like 3.14159.
What value can a Bool variable hold?
AAny number
BText only
Ctrue or false
DDecimal numbers
✗ Incorrect
Bool holds only true or false.
Which data type would you use to store the word "Hello"?
AString
BBool
CInt
DDouble
✗ Incorrect
String stores text like "Hello".
Why should you choose the right data type in Swift?
ATo make the app slower
BIt does not matter
CTo confuse other developers
DTo use memory efficiently and avoid errors
✗ Incorrect
Correct data types help the app run smoothly and prevent mistakes.
Explain the difference between Int and Double in Swift.
Think about numbers with and without decimals.
You got /3 concepts.
Describe when you would use a Bool and a String in an app.
Consider yes/no questions and words.
You got /3 concepts.
Practice
(1/5)
1. Which Swift data type is used to store true or false values?
easy
A. Int
B. Double
C. String
D. Bool
Solution
Step 1: Understand the data types
Bool stores true or false values, Int stores whole numbers, String stores text, and Double stores decimal numbers.
Step 2: Match the description to the type
Since the question asks for true or false values, the correct type is Bool.
Final Answer:
Bool -> Option D
Quick Check:
Bool = true/false [OK]
Hint: True/false values always use Bool type [OK]
Common Mistakes:
Confusing Bool with Int
Using String for true/false
Choosing Double for boolean values
2. Which of the following is the correct way to declare a Double variable named price with value 9.99 in Swift?
easy
A. var price: Double = 9.99
B. var price = "9.99"
C. var price Double = 9.99
D. var price: Int = 9.99
Solution
Step 1: Check variable declaration syntax
In Swift, to declare a variable with a specific type, use var name: Type = value.
Step 2: Identify the correct type and value
Since 9.99 is a decimal number, the type must be Double. var price: Double = 9.99 correctly declares price as Double with 9.99.
Final Answer:
var price: Double = 9.99 -> Option A
Quick Check:
Double declaration uses var name: Double = value [OK]
Hint: Use var name: Double = value for decimals [OK]
Common Mistakes:
Assigning decimal to Int
Using quotes for numbers
Omitting type when needed
3. What will be the output of this Swift code?
let number: Int = 5
let text: String = "5"
let isEqual = (number == Int(text)!)
print(isEqual)
medium
A. true
B. false
C. 5
D. Compilation error
Solution
Step 1: Understand the code logic
number is an Int with value 5, text is a String "5". Int(text) converts the string "5" to integer 5.
Step 2: Compare values
number == Int(text) compares 5 == 5, which is true. So isEqual is true and print outputs true.
Final Answer:
true -> Option A
Quick Check:
5 == 5 is true [OK]
Hint: Convert String to Int before comparing [OK]
Common Mistakes:
Comparing Int and String directly
Forgetting Int(text) conversion
Expecting string output
4. Identify the error in this Swift code snippet:
var isActive: Bool = "true"
print(isActive)
medium
A. print() cannot print Bool values
B. Bool cannot be assigned a String value
C. Variable name is invalid
D. Missing semicolon at end of line
Solution
Step 1: Analyze variable assignment
isActive is declared as Bool but assigned the string "true" (in quotes), which is incorrect.
Step 2: Understand type mismatch
Bool must be assigned true or false without quotes. Assigning a String causes a type error.
Final Answer:
Bool cannot be assigned a String value -> Option B
Quick Check:
Bool = true/false only, no quotes [OK]
Hint: Bool values are true or false without quotes [OK]
Common Mistakes:
Using quotes around true/false
Expecting semicolon error
Thinking print can't show Bool
5. You want to store a user's age, height in meters, full name, and whether they are a student. Which Swift data types should you use for these variables respectively?
hard
A. String, String, Int, Bool
B. Double, Int, Bool, String
C. Int, Double, String, Bool
D. Bool, Int, Double, String
Solution
Step 1: Match each data to its type
Age is a whole number -> Int, height with decimals -> Double, full name is text -> String, student status true/false -> Bool.
Step 2: Verify option matches order
Int, Double, String, Bool lists Int, Double, String, Bool in that order, matching the variables correctly.
Final Answer:
Int, Double, String, Bool -> Option C
Quick Check:
Whole number, decimal, text, true/false [OK]
Hint: Match data meaning: whole, decimal, text, true/false [OK]
Common Mistakes:
Mixing Int and Double
Using Bool for text
Confusing order of types
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.