Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline statement in Swift

I was working on a Swift tutorial and found that Swift has a strange way to handle multi-line statement.

First, I defined some extension to the standard String class:

extension String {
    func replace(target: String, withString: String) -> String {
        return self.stringByReplacingOccurrencesOfString(target, withString: withString)
    }

    func toLowercase() -> String {
        return self.lowercaseString
    }
}

This works as expected:

let str = "HELLO WORLD"
let s1 = str.lowercaseString.replace("hello", withString: "goodbye") // -> goodbye world

This doesn't work:

let s2 = str
            .lowercaseString
            .replace("hello", withString: "goodbye")
// Error: could not find member 'lowercaseString'

If I replace the reference to the lowercaseString property with a function call, it works again:

let s3 = str
            .toLowercase()
            .replace("hello", withString: "goodbye") // -> goodbye world

Is there anything in the Swift language specifications that prevent a property to be broken onto its own line?

Code at Swift Stub.

like image 479
Code Different Avatar asked Jun 04 '15 02:06

Code Different


1 Answers

This is definitely a compiler bug. Issue has been resolved in Xcode 7 beta 3.

like image 181
Code Different Avatar answered Nov 09 '22 14:11

Code Different