Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

swift - split now complains about missing "isSeparator"

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 == " " }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...