作者:大众化的公爵樱桃rwr_208 | 来源:互联网 | 2023-07-26 11:24
IhaveasimpleNSManagedObjectsubclass:我有一个简单的NSManagedObject子类:@objcclassMyModel:NSManagedO
I have a simple NSManagedObject
subclass:
我有一个简单的NSManagedObject子类:
@objc class MyModel: NSManagedObject {
@NSManaged var myProperty: String
}
However, the following code:
但是,以下代码:
var model = NSEntityDescription.insertNewObjectForEntityForName("MyModel", inManagedObjectContext: managedObjectContext) as MyModel
assert(model != nil) // passes
if model.myProperty != nil { //crashes
println("not nil")
}
crashes at if model.myProperty != nil
with a EXC_BAD_ACCESS
. Why is this happening? This only started happening with Beta 5, and worked properly with Beta 4.
如果model.myProperty!= nil,则使用EXC_BAD_ACCESS崩溃。为什么会这样?这仅在Beta 5中开始,并且与Beta 4一起正常运行。
The above class was automatically generated using Xcode, so they did not add a ?
to the end of the property. However, manually adding a ?
to the end of the property does resolve the issue (@NSManaged var myProperty: String?
).
上面的类是使用Xcode自动生成的,所以他们没有添加?到了财产的尽头。但是,手动添加?到属性的末尾确实解决了问题(@NSManaged var myProperty:String?)。
My question is, why doesn't Xcode automatically add the question mark to make it optional if it is marked as such in the schema, and why was this not an issue in previous betas?
我的问题是,为什么Xcode不会自动添加问号以使其成为可选的,如果它在架构中被标记为这样,为什么这在以前的测试版中不是问题?
2 个解决方案