1

I have just updated Xcode 7 to beta5 and have found out that the split function is replaced with split method. I am not that experienced in Swift yet to figure out how to update my current code to the new syntax.

let components = split(name.characters){$0 == "."}.map { String($0) }
// 'split(_:maxSplit:allowEmptySlices:isSeparator:)' is unavailable: Use the split() method instead.
driver733
  • 401
  • 2
  • 6
  • 21

1 Answers1

7

If split function was replaced by a split method, then shouldn't the new code look like this?

let components = name.characters.split {$0 == "."}.map { String($0) }
AliSoftware
  • 32,623
  • 6
  • 82
  • 77
  • If it`s not hard, could you please explain the syntax used in this line of code. I feel kind of lost here :( – driver733 Aug 07 '15 at 13:30
  • What don't you understand from the above syntax? I'd think maybe the syntactic sugar used here that allowed us to avoid using parentheses to specify the parameters, but you already have that on your call of `map { … }` so not sure if that's what is bothering you… If you find it more readable, you could write that line without using the "trailing closure" syntax (allowing us not to put the last param inside parenthesis if it's a closure): `let components = name.characters.split({$0 == "."}).map({ String($0) })` – AliSoftware Aug 07 '15 at 20:52