Question:

When this code is executed, what is the value of the swift string?

import Foundation
let ns = NSString("Hello")
let swift = String(ns)

Answer:

Correct answer: This code will not compile.

Explanation: While it is possible to typecast an NSString into a String using an initializer without a label, it is not possible the other way around. The code should read let ns = NSString(string: "Hello").


Keywords:

© 2017 QuizBucket.org