Question:

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

var names = [String]()
names.append("Amy")

let example1 = names.popLast()
let example2 = names.popLast()

Correct answer: nil.

Explanation: The popLast() method returns an optional version of the data type the array contains, which in this code is a String?. As the only string in the array was already removed, the second call will return nil.

 


Keywords:

© 2017 QuizBucket.org