Swift Question

split json string with downcast "!" not works


/Users/alexik/Documents/Programming/Swift/college-app/College App Test/ConversationDialogViewController.swift:394:50: 'split(_:maxSplit:allowEmptySlices:isSeparator:)' is unavailable: Use the split() method instead.


let name = "Bestand: " + split(json["name"].string!) {$0 == "/"}[1]


I don't see on Stack Overflow the same issue. There are a lot of examples like this:

string[] lines = entry_text.Split(new string[] {"\n"}, StringSplitOptions.None);

Answer

split is no longer a global function. It is now an extension on collection types. In your case you would call it like:

let name = "Bestand: " + String(json["name"].string!.characters.split { $0 == "/" }[1])