我有以下字符串
var points = "4,5"
我想转换为可变数组,因此它变为[4,5] 我尝试了以下但是没有用
var points = "4,5"
var selectedArray : NSMutableArray = [points]
答案 0 :(得分:27)
Swift 2:
你走了:
var points = "4,5"
var pointsArr = split(points) {$0 == ","}
或
var pointsArr = points.componentsSeparatedByString(",")
来源:Swift: Split a String into an array
斯威夫特3:
如gomfucius所述:
var arr = points.components(separatedBy: ",")