Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
swift中的可变副本_Swift_Nsmutablearray - Fatal编程技术网

swift中的可变副本

swift中的可变副本,swift,nsmutablearray,Swift,Nsmutablearray,可以得到一个可变副本,如(obj-c) 斯威夫特 我正在尝试重新安排一些核心数据实体 func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) 有什么想法吗?如果数据是值类型(结构、数组、字典、字符串等),只需将不可变变量分配给可变变量: let immutable = [1, 2,

可以得到一个可变副本,如(obj-c)

斯威夫特

我正在尝试重新安排一些核心数据实体

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