Question:

What output will be produced by the code below?

import Foundation
let crew = NSMutableDictionary()
crew.setValue("Kryten", forKey: "Mechanoid")
print(crew.count)

Correct answer: 1.

Explanation: Although we've declared the NSMutableDictionary to be constant, it's a reference type and so will happily mutate itself regardless of its supposed "constant" status. So, this code will output 1 because the value was added successfully.


Keywords:

© 2017 QuizBucket.org