When this code is executed, what will example2 be set to?

var names = [String]()
let example1 = names.removeLast()
let example2 = names.removeLast()

Correct answer: This code will compile but crash.

Explanation: The removeLast() method returns the same data type as the array contains, which in this code is a String. As the only string in the array was already removed, the second call will throw an exception and crash.



© 2017