When I create an entity using core data then generate a subclass of NSManagedObject from it I get the following output (in the .h):
@class Foo;
@interface Foo : NSManagedObject
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSSet *otherValues;
@end
However, in my .m file I want to make use of the name and otherValues values. Normally I would simply create a couple of ivars and then add the properties for them as I required. That way I can access them in my .m file easily.
In this situation would it be acceptable to do this? Would adding ivars to the .h (for name and otherValues) cause any unusual behaviour in the persistance & retrieval of objects?
You don’t use instance variable to access attributes of Core Data managed objects.
The generated implementation file contains the statements
which means that the getter/setter functions for the Core Data properties are created dynamically, e.g. to retrieve the value from the managed object context or from the underlying persistent store.
So you should always use the properties to access the attributes, for example:
Alternatively, you can use the key-value methods:
See also: Modeled Properties in the “Core Data Programming Guide”: