【发布时间】:2016-08-02 09:30:19
【问题描述】:
我正在尝试在 swift 中以编程方式为现有的实体创建一个新的属性。
这是我的代码:
let model = NSManagedObjectModel()
var properties = Array<NSAttributeDescription>()
let remoteURLAttribute = NSAttributeDescription()
remoteURLAttribute.name = "\(foundArray[indexPath.row]) id"
remoteURLAttribute.attributeType = .stringAttributeType
remoteURLAttribute.isOptional = false
remoteURLAttribute.isIndexed = true
properties.append(remoteURLAttribute)
entity?.properties = properties
model.entities = [entity!]
应用程序总是因为这个错误而崩溃:
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'不能修改不可变的 模型。'
我该如何解决这个问题?
【问题讨论】:
标签: ios swift xcode core-data swift3