You can
- trim the
[ and ] characters with stringByTrimmingCharactersInSet;
- split it into an array of components separated by commas; and
- trim whitespace around each item.
For example:
let array = [12,33,22,44];
let string = array.description; // result is "[12, 33, 22, 44]", not "[12,33,22,44]"
let results = string
.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "[]"))
.componentsSeparatedByString(",")
.map { return $0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) }
Or if you want an array of integers instead of an array of strings:
let results = string
.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "[]"))
.componentsSeparatedByString(",")
.map { return $0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).toInt()! } // remove `!` if you're not assured that only integers will be present
datais an array.