0
0
Swiftprogramming~20 mins

What is Swift - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is Swift primarily used for?

Swift is a programming language created by Apple. What is its main use?

ABuilding iOS, macOS, watchOS, and tvOS apps
BCreating Android applications
CDeveloping Windows desktop software
DWriting server-side scripts only
Attempts:
2 left
💡 Hint

Think about which devices Apple makes and what language they promote for app development.

Predict Output
intermediate
2:00remaining
What is the output of this Swift code?

Look at this Swift code and choose the output it produces.

Swift
let greeting = "Hello"
let name = "Sam"
print("\(greeting), \(name)!")
AError: Cannot print variables this way
Bgreeting, name!
CHello, Sam!
DHello name!
Attempts:
2 left
💡 Hint

Check how variables are inserted inside strings in Swift.

Predict Output
advanced
2:00remaining
What does this Swift code print?

Analyze the code and select the output it produces.

Swift
var numbers = [1, 2, 3, 4, 5]
let doubled = numbers.map { $0 * 2 }
print(doubled)
AError: map function not found
B[1, 2, 3, 4, 5]
C[1, 4, 9, 16, 25]
D[2, 4, 6, 8, 10]
Attempts:
2 left
💡 Hint

Remember that map applies a function to each item in the array.

🔧 Debug
advanced
2:00remaining
What error does this Swift code raise?

Find the error in this Swift code snippet.

Swift
let number: Int = "123"
print(number)
AType mismatch error
BSyntax error: missing semicolon
CNo error, prints 123
DRuntime error: nil value
Attempts:
2 left
💡 Hint

Check if the type on the left matches the value on the right.

🧠 Conceptual
expert
2:00remaining
Which feature makes Swift safe and fast?

Swift is known for safety and speed. Which feature helps achieve this?

AUsing dynamic typing for flexibility
BOptionals to handle absence of values safely
CManual memory management like in C
DNo type checking at compile time
Attempts:
2 left
💡 Hint

Think about how Swift avoids crashes from missing values.