split now complains about missing "isSeparator"
Asked Answered
C

1

11

After the latest upgrade of Swift 1.2, I can't figure out how to split a line of text into words. I used to do this:

let bits = split(value!, { $0 == " "}, maxSplit: Int.max, allowEmptySlices: false)

But that no longer works, because...

Cannot invoke 'split' with an argument list of type '(String, (_) -> _, maxSplit: Int, allowEmptySlices: Bool)'

Ummm, ok, even though I could last build? Well whatever, let's try...

let bits = split(value!, { $0 == " "})

Well that and every other version I can think of ends up saying:

Missing argument for parameter 'isSeparator' in call

Let's hear it for beta-testing new programming languages! Yay!

Anyone know the correct secret sauce for 1.2?

Cortneycorty answered 25/2, 2015 at 18:25 Comment(0)
F
16

It seems that the order of the parameters changed in Swift 1.2:

let bits = split(value!, maxSplit: Int.max, allowEmptySlices: false,
                 isSeparator: { $0 == " "})

or, using the default values:

let bits = split(value!, isSeparator: { $0 == " "})

The predicate is now the last parameter and requires an external parameter name isSeparator because it is preceded by optional parameters.

The advantage of this change is that you can use the trailing closure syntax:

let bits = split(value!, maxSplit: Int.max, allowEmptySlices: false) { $0 == " " }

or

let bits = split(value!) { $0 == " " }
Filature answered 25/2, 2015 at 18:34 Comment(2)
LOLZ. Thanks Apple. And non-sarcastic thanks to Martin, this does indeed fix the problem.Cortneycorty
Yes, thanks Apple. It's possible the change in the split function caused a particularly nasty bug I experienced with a Release mode build (see my answer here: #29107777).Bijou

© 2022 - 2024 — McMap. All rights reserved.