1

The error: Cannot invoke 'split' with an argument list of type '(String, (String) -> Bool)'

Code i want to use: let nameArr = split(name) {$0 == "."}

1

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

6 Comments

am getting an error Initializer for conditional binding must have Optional type, not 'NSURL'
Provide the declaration of your variable name, see my answer
am really new to swift so idk what to do here is the error Image
I saw you error , but what's the problem? you can't use the split in this way anymore , you need to change your line let nameArr = split(name) {$0 == "."} for any of the above I explained you.
sorry for being a pain but neither of them worked for me each one shows an error in a different way like for example look at this image
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.