swift - Core Data generates an NSManagedObject subclass with a property of type NSNumber, but it's a Bool -
i created core data data model , added entities. i'm generating nsmanagedobject subclasses.
in generated code, found 1 of properties, type "boolean" in data model, has turned property of type nsnumber!
that's not correct, thought. nsnumber not boolean. why doesn't use bool type?
then thought might 1 of annoying things of objective-c. think int , double, bool cannot saved core data has use nsnumber. right?
how convert nsnumber bool , how convert bool nsnumber? maybe 0 = false , 1 = true? other values? isn't type-safe @ all...
for question how convert nsnumber bool , how convert bool nsnumber? u can below, nsnumber objects
//convert bool number nsnumber *boolinnumber = [nsnumber numberwithbool:yes]; //or no //get back, convert number bool nsnumber *anum = [nsnumber numberwithbool:yes]; //get nsnumber instance bool numberinbool = [anum boolvalue]; and aslo u can convert other types, more info check class reference hear
sorry delay, , swift version,
var numinbool:nsnumber? //is nsnumber instance numinbool = nsnumber(bool: true) //get number bool (number in bool) var boolinnum:bool? //it boolean boolinnum = numinbool!.boolvalue //get bool number (bool number) yes right... :) per @fred doc said,
let numinbool = nsnumber(bool: true) let boolinnum = numinbool.boolvalue
Comments
Post a Comment