I have the following string
var points = "4,5"
I would like to convert to a mutable array so it becomes [4,5] I tried the following but it did not work
var points = "4,5"
var selectedArray : NSMutableArray = [points]
Swift 2:
Here you go:
var points = "4,5"
var pointsArr = split(points) {$0 == ","}
or
var pointsArr = points.componentsSeparatedByString(",")
Source: Swift: Split a String into an array
Swift 3:
as gomfucius mentioned:
var arr = points.components(separatedBy: ",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With