Can someone walk me through how to ‘hide’ the standard core data setters?
I know there is not really a way to define ‘Private’ methods in Objective-C, but read about using an extension to achieve a similar result. The problem is, I want to apply this to core data classes. I would like to hide the standard setters created for some attributes, and only call them from inside other, exposed setters.
An example: My core data object has a BOOL ‘collected’ and a date ‘dateCollected’. I have figured out how to add setDateCollected to setCollected, but now I would like to ‘hide’ set collected so that it can’t be called directly so easily (when I might forget to also set dateCollected manually).
To clarify, the part that is tripping me up is the ‘@dynamic’ calls – I don;t know where these should live.
EDIT – I guess I missed a part. I can move the @property declaration into the implementation file just fine. But I want the setter to be hidden, and the getter to remain public. I guess I need to replace the @property, but I don’t know how to do this for a core data object.
You define private methods in the implementation file. If a method is not shown in the header file, then by definition, it is private. To clarify, the following is how you define public properties and methods.
In the implementation file, you can define private properties and methods as follows.
… etc.
This description is for iOS 5 of course. The syntax for iOS3 & 4 is similar except that the private instant variables (iVars) appear in the header file–which could be very confusing for newbies. iOS 5 cleaned this up, by not requiring instant variables to appear anywhere.