Access to contents of class extension


In the book, says:
First, objects that are not instances of BNREmployee can no longer see this property. For instance, a non-BNREmployee object could attempt to access an employee’s alarm code like this:
BNREmployee *mikey = [[BNREmployee alloc] init];
unsigned int mikeysCode = mikey.officeAlarmCode;

I sort of get this. However it seems like mikey is a BNREmployee & mikey is accessing officeAlarmCode (e.g. mikey.officeAlarmCode is the same as [mikey officeAlarmCode] and the output is being stored in mikeysCode (which is not a BNREmployee).

Can someone clarify this idea?

What’s are some examples of a BNREmployee accessing an officeAlarmCodes?


If you try to access the officeAlarmCode in main.m then it is not going to show up because that property is only visible in BNREmployee.m. The main.m only has access to the BNREmployee header file. Just for fun I even tried import “BNREmployee.m” in main then tried to access the officeAlarmCode. Looks like it would let me and the red dots would go away but when I tried to build the project it would bomb out. I’m guessing it only likes header files in the import area I guess. You can access the officeAlarmCode in main through a method built inside BNREmployee.m. But that’s about it.


// Create an instance of BNREmployee
BNREmployee *adam = [[BNREmployee alloc]init];
 adam.firstName = @"Adam";
// This code fails  adam.officeAlarmCode = 1234;
unsigned int officeCode = [adam officeCodeHack];
NSLog(@"%u", officeCode);


//A class extension
@interface BNREmployee ()
@property (nonatomic) NSMutableArray *assets;
@property (nonatomic) unsigned int officeAlarmCode;


@implementation BNREmployee

- (unsigned int) officeCodeHack {
    self.officeAlarmCode = 1234;
    return self.officeAlarmCode;