swift - Core data Int16 as optional -
in swift, how make
nsmanaged int16
propertyoptional
this:nsmanaged var durationtype: int16?
i'm getting compiler error:
roperty cannot marked @nsmanaged because type cannot represented in objective-c
if not possible, , check
optional
box in core data model editor, how check if property has value when coming database?
you can make property optional , keep int16
. key @nsmanaged
not required, if remove it, must implement own accessor methods.
one possible implementation:
var durationtype: int16? { { self.willaccessvalueforkey("durationtype") let value = self.primitivevalueforkey("durationtype") as? int self.didaccessvalueforkey("durationtype") return (value != nil) ? int16(value!) : nil } set { self.willchangevalueforkey("durationtype") let value : int? = (newvalue != nil) ? int(newvalue!) : nil self.setprimitivevalue(value, forkey: "durationtype") self.didchangevalueforkey("durationtype") } }
Comments
Post a Comment