I have been learning Objective-C from Big Nerd Ranch Book. I am stuck on 21st chapter example code.
Here is class BNREmployee header and Main file code.
Header
@interface BNREmployee : BNRPerson
{
NSMutableArray *_assets;
}
@property (nonatomic) unsigned int employeeID;
@property (nonatomic) unsigned int officeAlarmCode;
@property (nonatomic) NSDate *hireDate;
@property (nonatomic, copy) NSArray *assets;
- (double)yearsOfEmployment;
- (void)addAsset:(BNRAsset *)a;
- (unsigned int)valueOfAssets;
@end
Main.m
for (int i = 0; i < 10; i++) {
// Create an instance of BNREmployee
BNREmployee *mikey = [[BNREmployee alloc] init];
// Give the instance variables interesting values
mikey.weightInKilos = 90 + i;
mikey.heightInMeters = 1.8 - i/10.0;
mikey.employeeID = i;
// Put the employee in the employees array
[employees addObject:mikey];
}
So, my question is how are we creating multiple objects for BNREmployee class with same name i.e., 'mikey'. It is done inside the loop. But, how does it work, why the compiler is allowing that? Thanks
nameproperty). Pointers have names. Entirely different things (and a fundamental point you should understand BEFORE trying to code in Objectiver-C).