Reputation: 23
The error: Cannot invoke 'split' with an argument list of type '(String, (String) -> Bool)'
Code i want to use: let nameArr = split(name) {$0 == "."}
Upvotes: 1
Views: 2301
Reputation: 23459
Strings are No Longer Collections, String
no longer conforms to CollectionType
. You can use other alternatives like the function componentsSeparatedByString
:
var name = "Victor.Hello.GYTT"
let nameArr = name.componentsSeparatedByString(".") // [Victor, Hello, GYTT]
Another option is using the characters
property:
let nameArr = split(name.characters) { $0 == "." }.map { String($0) }
With the new .init
syntax in Xcode 7 beta 2, where init
"can now be referenced like static methods" like in the following way:
let nameArr = split(name.characters) { $0 == "." }.map { String.init }
Or making the String
conforms the protocol too, but Apple made a decision to remove String
conformance to Sliceable
, be carefull.
You can read more about notables changes in Changes to the Swift Standard Library in 2.0 beta 1 in the blog of @AirSpeedVelocity. Really nice.
I hope this help you.
Upvotes: 4