Questions, Tips and Tricks to clear iOS Interview Questions

Photo from Unsplash
I hope the interview series I published before helped you a lot to understand the iOS developer interview process and brush up with a few interesting topics. Now for a change lets try to test our skills with the below Questions:
📜 This article is for junior iOS developers
Q1. What output will be produced by the code below?
var crew = ["Captain": "Malcolm", "Doctor": "Simon"]
crew = [:]
print(crew.count)
Options
- 0
- 1
- 2
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q2. What output will be produced by the code below?
let number = 5
switch number {
case 0..<5:
print("First group")
case 5...10:
print("Second group")
case 0...5:
print("Third group")
default:
print("Fourth group")
}
Options
- First group
- Second group
- Third group
- Fourth group
- Nothing will be output
- This code will compile but crash
Q3. When this code is executed, what will the numbers constant contain?
let numbers = [1, 2, 3].map { [$0, $0] }
Options
- [1, 1, 2, 2, 3, 3]
- [1, 2, 3]
- [[1, 1], [1, 2], [1, 3]]
- [[1, 1], [2, 1], [3, 1]]
- [[1, 1], [2, 2], [3, 3]]
- [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
- This code will compile but crash
- This code will not compile
Q4. What output will be produced by the code below?
var spaceships = Set<String>()
spaceships.insert("Serenity")
spaceships.insert("Enterprise")
spaceships.insert("TARDIS")
spaceships.insert("Serenity")
print(spaceships.count)
Options
- 0
- 1
- 3
- 4
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q5. What output will be produced by the code below?
let rounded: Int = round(10.5)
print("Rounding 10.5 makes \(rounded)")
Options
- Rounding 10.5 makes 10
- Rounding 10.5 makes 10.5
- Rounding 10.5 makes 11
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q6. What output will be produced by the code below?
func greet(_ name: inout String) {
name = name.uppercased()
print("Greetings, \(name)!")
}
var name = "Mal"
greet(name)
print("Goodbye, \(name)!")
Options
- Greetings, MAL!
Goodbye, MAL!
- Greetings, MAL!
Goodbye, Mal!
- Greetings, Mal!
Goodbye, MAL!
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q7. What output will be produced by the code below?
let point = (556, 0)
switch point {
case (let x, 0):
print("X was \(x)")
case (0, let y):
print("Y was \(y)")
case let (x, y):
print("X was \(x) and Y was \(y)")
}
Options
- X was 556
- X was 556 and Y was 0
- Y was 0
- Nothing will be output
- This code will compile but crash
- This code will not compile
- [Type an answer here]
Q8. Read the code below:
var foo: Float = 32
var bar: Double = 32
Assuming no typecasting, which of the following statements is true?
Options
- Either variable can be assigned to the other
- Neither variable can be assigned to the other
- You can assign "bar" to "foo"
- You can assign "foo" to "bar"
- This code will compile but crash
- This code will not compile
Q9. What output will be produced by the code below?
let people = [String](repeating: "Malkovitch", count: 2)
print(people)
Options
- "Malkovitch" (a string)
- "Malkovitch", "Malkovitch" (two strings)
- ["Malkovitch", "Malkovitch"] (an array)
- ["Malkovitch"] (an array)
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q10. When this code is executed, what value does the result contain?
func sum(numbers: Int...) -> Int {
var result = 0
for number in numbers {
result += number
}
return result
}
let result = sum(numbers: [1, 2, 3, 4, 5])
Options
- 0
- 1, 2, 3, 4, 5
- 15
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q11. What output will be produced by the code below?
let crew = NSMutableDictionary()
crew.setValue("Kryten", forKey: "Mechanoid")
print(crew.count)
Options
- 0
- 1
- nil
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q12. What output will be produced by the code below?
enum MyError: Error {
case broken
case busted
case badgered
}
func willThrowAnError() {
throw MyError.busted
}
do {
try willThrowAnError()
} catch MyError.busted {
print("Code was busted!")
} catch {
print("Code just didn't work")
}
Options
- "Code just didn’t work"
- "Code was busted!"
- Nothing will be output
- This code will compile but crash
- This code will not compile
Q13. When this code is executed, what will the numbers constant contain?
let numbers = [1, 2, 3].flatMap { [$0, $0] }
Options
- [1, 1, 2, 2, 3, 3]
- [1, 2, 3]
- [[1, 1], [1, 2], [1, 3]]
- [[1, 1], [2, 1], [3, 1]]
- [[1, 1], [2, 2], [3, 3]]
- [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
- This code will compile but crash
- This code will not compile
Q14. When this code is executed, what data type does converted number have?
let possibleNumber = "1701"
let convertedNumber = Int(possibleNumber)
Options
- Int
- Int?
- String
- This code will not compile
Q15. What output will be produced by the code below?
let names = ["Pilot": "Wash", "Doctor": "Simon"]
let doctor = names["doctor"] ?? "Bones"
print(doctor)
Options
- ""
- "Bones"
- "Doctor"
- "Simon"
- "Wash"
- nil
- Nothing will be output
Answers:
- (1) 0
- (2) Second group
- (5) [[1, 1], [2, 2], [3, 3]]
- (3) 3
- (6) This code will not compile
- (6) This code will not compile
- (1) X was 556
- (2) Neither variable can be assigned to the other
- (3) ["Malkovitch", "Malkovitch"] (an array)
- (7) This code will not compile
- (2) 1
- (5) This code will not compile
- (1) [1, 1, 2, 2, 3, 3]
- (2) Int?
- (2) "Bones"
Thank you! will meet you in part 2 with a different set of questions 🚀
References:
Swift By Sundell
Hacking With Swift
Raywenderlich
Swift Documentation by Apple