[英]How to Convert NSMutable Array to Swift Array?
I am adding ID's to NSMutableArray
after that i want this MutableArrray
as a Swift Array. 之后,我想将这个
MutableArrray
作为Swift数组添加到NSMutableArray
。
here's my code: 这是我的代码:
var categories = NSMutableArray()
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (!categoryTable.hidden)
{
print("select multiple categories")
categoryList = categoryData[indexPath.row]
categories.addObject(["\(categoryList!.categoryID)"])
}
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let listCategoryID = categoryData[indexPath.row]
for category in categories as [AnyObject]
{
if("\(listCategoryID.categoryID)" == category.objectAtIndex!(0) as! String)
{
categories.removeObject(category)
}
}
print("Catgeory ID \(categories)")
}
// Convert NSMutableArray To Swift Array
@IBAction func saveBtnPressed(sender: AnyObject) {
let catgID = categories as AnyObject as! [String]
}
Output I am Getting: Category ID ( ( 27 ), ( 26 ) ) 我得到的输出:类别ID((27),(26))
Output I want : ["27","26"] 我想要的输出:[“ 27”,“ 26”]
var catg_id:[Int] = []
for category in categories as [AnyObject]
{
catg_id.append(Int(category.objectAtIndex!(0) as! NSNumber))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.