Swift将逗号分隔的字符串转换为NSMutableArray

时间:2015-06-07 19:17:05

标签: swift

我有以下字符串

var points = "4,5"

我想转换为可变数组,因此它变为[4,5] 我尝试了以下但是没有用

   var points = "4,5" 
   var selectedArray : NSMutableArray = [points]

1 个答案:

答案 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: ",")