Swift: When Cocoa and Swift collide

Consider the following code. Notice anything…unusual?

init(host: String) {
        self.host = host
        self.protectionSpace = NSURLProtectionSpace(host: self.host, port: 0, `protocol`: 
            "http", realm: nil, authenticationMethod: nil)

Specifically, check out those back ticks used in-line as part of the method signature. They’re required here because the word protocol, in addition to being part of the method name, is a reserved word in Swift. The back ticks enable you to differentiate reserved words and identifiers.

Comments are closed.