Home > iOS Programming > Quizzes > Swift Programming Quiz
Swift Programming Quiz
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 11% Most missed: “What is the error in this code?”

Swift Programming  MCQs For LinkedIn Skill Assessments.

Swift Programming Quiz
Time left 00:00
25 Questions

1. What is wrong with this code?
swift
for (key, value) in [1: 'one', 2: 'two']{
print(key, value)
}
2. What is the value of 'val' after this code is executed?
swift
let i = 5
let val = i * 6.0
3. What are the contents of 'vals' after this code is executed?
swift
var vals = [10, 2]
vals.sort { (s1, s2) -> Bool in
s1 > s2
}
4. Which of these choices is associated with unit testing?
5. What will this code print to the console?
swift
var items = ['a':1, 'b':2, 'c':'test'] as [String: Any]
items['c'] = nil
print(items['c'] as Any)
6. When is deinit called?
7. Which object allows you access to specify that a block of code runs in a background thread?
8. What is the error in this code?
swift
extension String {
var firstLetter: Character = 'c' {
didSet {
print('new value')
}
}
}
9. What is the error in this code?
swift
let x = 5
guard x == 5 { return }
10. In the function below, what are 'this' and 'toThat' examples of?
swift
func add(this x: Int, toThat y: Int)->{}
11. How many values does vals have after this code is executed?
swift
var vals = Set = ['4', '5', '6']
vals.insert('5')
12. What is the inferred type of x?
swift
let x = ['a', 'b', 'c']
13. What does this code print to the console?
swift
var userLocation: String = 'Home' {
willSet(newValue) {
print('About to set userLocation to \(newValue)...')
}
didSet {
if userLocation != oldValue {
print('userLocation updated with new value!')
} else {
print('userLocation already set to that value...')
}
}
}
userLocation = 'Work'
14. DispatchQueue.main.async takes a block that will be
15. How can you avoid a strong reference cycle in a closure?
16. What is printed to the console when this code is executed?
swift
't'.forEach { (char) in
print(char)
}
17. What's wrong with this code?
swift
class Person {
var name: String
var address: String
}
18. What does this code print?
swift
enum Positions : Int {
case first, second, third, other
}
print (Positions.other.rawValue)
19. How many times this code will be executed? —OR— How many times will this loop be performed?
swift
for i in ['0', '1']{
print(i)
}
20. What is the type of 'vals' in this code?
swift
let vals = ['a', 1, 'Hi']
21. What is wrong with this code?
swift
let val = 5.0 + 10
22. What is the type of value1 in this code?
swift
let value1 = '\('test'.count)'
23. What does this code print?
swift
typealias Thing = [String:Any]
var stuff: Thing
print(type(of: stuff))
24. What is this code an example of?
swift
let val = 5
print('value is: \(val)')
25. What prints to the console when executing this code?
swift
let x = try? String.init('test')
print(x)