2015年3月12日 星期四

swift CoreData EXC_BAD_ACCESS (code=1, address=0x0) when access empty property

http://www.tagwith.com/question_394893_coredata-exc-bad-access-code-1-address-0x0-when-access-empty-property

Did you specify default values for your attributes in your XCDataModel? 
If you generate an NSManagedObject subclasses you can change any attribute to an optional by adding a question mark to the declaration:
@NSManaged var stringProperty: String?
@NSManaged var dateProperty: NSDate?
Elsewhere you can do:
println(m.stringProperty?)
if m.stringproperty != nil {
// do stuff
}

沒有留言:

張貼留言