I've read the other threads but they only seem to deal with single character delimiters, and I think Playground is crashing for me because I use more than one char.
"[0, 1, 2, 1]".characters
.split(isSeparator: {[",", "[", "]"].contains($0)}))
.map(String.init) //["0", " 1", " 2", " 1"]
You could use .stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
to remove the spaces:
"[0, 1, 2, 1]".characters.split(isSeparator: {[",", "[", "]"].contains($0)}).map({String($0).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())})
Gives:
["0", "1", "2", "1"]