I was working on a Swift tutorial and found that Swift has a weird way of handling a multi-line statement.
First, I defined some extension of 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")
This does not work:
let s2 = str .lowercaseString .replace("hello", withString: "goodbye") // Error: could not find member 'lowercaseString'
If I replace the reference to the lowercaseString property lowercaseString function call, it will work again:
let s3 = str .toLowercase() .replace("hello", withString: "goodbye")
Is there anything in the Swift language specs that prevent a property from being split on its own line?
Code in Swift Stub .
source share