swift中的可变副本
可以得到一个可变副本,如(obj-c) 斯威夫特 我正在尝试重新安排一些核心数据实体swift中的可变副本,swift,nsmutablearray,Swift,Nsmutablearray,可以得到一个可变副本,如(obj-c) 斯威夫特 我正在尝试重新安排一些核心数据实体 func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) 有什么想法吗?如果数据是值类型(结构、数组、字典、字符串等),只需将不可变变量分配给可变变量: let immutable = [1, 2,
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)
有什么想法吗?如果数据是值类型(结构、数组、字典、字符串等),只需将不可变变量分配给可变变量:
let immutable = [1, 2, 3]
var mutable = immutable
mutable[0] = 55 // mutable now is [55, 2, 3], whereas immutable is of course not modified
如上所述,这只适用于值类型,因为赋值是通过值而不是引用完成的
(self.fetchedResultsController.fetchedObjects as NSArray).mutableCopy() as! NSMutableArray
(self.fetchedResultsController.fetchedObjects as NSArray).mutableCopy() as! NSMutableArray