kris
kris

Reputation: 2526

Core Data primitive accessor methods valid for iPhone?

I'm getting mixed signals as to whether primitive accessor methods (of the form setPrimitive*YourAttribute* vs setPrimitiveValue:*value* forKey:@"*YourAttribute*" in Core Data objects are meant for use with iPhone code or just Mac. On the one hand, the Apple documentation doesn't seem to mention them as available for iOS, just Mac OS X v10.5. On the other hand, they work with my iPhone app's code, albeit with compiler warnings, e.g. "Method xxxx not found (return type defaults to 'id')".

Can someone confirm one way or another?

Upvotes: 2

Views: 1166

Answers (2)

Fabio Russo
Fabio Russo

Reputation: 412

You could use NSNumber instead. For bools you would have and [NSNumber numberWithInt:0] for NO and [NSNumber numberWithInt:1] for YES for example. Same logic with integers, doubles, float. It's much easier this way. Your property would be like: NSNumber *myInteger , you would only have to box and unbox it when you retrieve or store it. That's how I would do it.

Upvotes: 0

pe8ter
pe8ter

Reputation: 1263

In the Overview of the Managed Object Accessor Methods section of Core Data Programming Guide it states that primitive accessors are automatically generated for you, but you will need to declare the properties to suppress compiler warnings. You say using primitive accessors works in your code (even with the warnings) so it seems like it's supported in iOS.

It appears that Apple's documentation pages aren't always rigorous in mentioning a given feature's availability in the various OSes.

Upvotes: 2

Related Questions