you said that ‘mikey’ is a non-BNREmployee object.
but i think ‘mikey’ is ‘BNREmployee object’?
i don’t know why you say that mikey is ‘non-BNREmployee object’?
so i think ‘mikey’ is employee object variable, so it can access its alarm code of private property.
but it can’t.
teach me why it can’t access its alarm code. plz.
[quote][code]//BNREmployee.m @interface BNREmployee () @property (nonatomic) unsigned int officeAlarmCode; @end
@implementation BNREmployee[/code][/quote]
A BNREmployee object can access the officeAlarmCode property in the implementation file.
However, since the property is declared in the implementation file as a private property, if you try to access it from outside of the implementation file, for example in main.m, you will get an error at compilation time.
I’m still a little bit puzzled by this same part in the chapter by the way.
The way the book reads, it’s saying that an object that is an instance of the class BNREmployee can in fact still access the officeAlarmCode method. In this particular example mikey is literally a pointer to an instance of BNREmployee and, how I understand it, should have access to this particular method.
On the other hand, if I assume that anything that tries to access the method officeAlarmCode outside of the implementation file, wether it be an instance of BNREmployee or not will fail, it makes more sense.
Or is the fact that mikey is a pointer and not an actual instance of the object the fact it’s not working? If so, is there a way to access this method in main.m after all?
Little bit confused by this little snippet.
Edit: I just realised how this actually works and think the book leaves out an important bit of information for this part in the chapter to really make sense. What effectively happens by moving the ivar officeAlarmCode to a class extension is that it becomes impossible to set or get the ivar. I believe what needs to be added additionally after adding it to the class extension, are new methods to set, get and/or remove values to the ivar.
Is that the unsigned int called mikeysCode (which is NOT an instance of BNREmployee) can NOT then ask mikey (who IS an instance of BNREmployee) for his officeAlarmCode.
So:
unsigned int mikeyCode = (remember that = is not equals but set this variable to the next thing)
is not able to access
mikey.officeAlarmCode
Does that help explain it better fly2web and Arthurzwit?
Why would you need to declare a setter if the officeAlarmCode is declared as a @property in BNREmployee.m as the book says? I thought that a @property was suppose to synthesize a setter and a getter.