Another question of Object instance Variables


#1
#import <Foundation/Foundation.h>
#import "BNREmployee.h"
#import "BNRAsset.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        NSMutableArray *employees = [[NSMutableArray alloc] init];
        
        for (int i = 0; i < 10; i++) {
            BNREmployee *mikey = [[BNREmployee alloc] init];
            mikey.weightInKilos = 96 + i;
            mikey.heightInMeters = 1.8 - i/10.0;
            mikey.employeeID = i;
            [employees addObject:mikey];
            
            NSLog(@"%u", [mikey employeeID]);  //okay!!
            NSLog(@"%u", mikey.employeeID);   // okay!!
            NSLog(@"%u", [employees[i]  employeeID]);  // okay!!
            NSLog(@"%u", employees[i].employeeID); // error occurred!! 
        }

this is part of full coding.
“employeeID” is property so dot expression(“employees[i].employeeID”) and
message sending expression ("[employees[i] employeeID]")
both possible?
but why “employees[i].employeeID” is error occurred?
i don’t know? why?


#2

[quote][code]
NSMutableArray *employees = [[NSMutableArray alloc] init];

for (int i = 0; i < 10; i++) {

NSLog (@"%u", employees[i].employeeID); // error occurred!!
}[/code][/quote]
That’s because the compiler couldn’t determine what the type of the expression employees[i] is.

You must specify the type:

NSLog (@"%u", ((BNREmployee *)employees[i]).employeeID);

// Or
BNREmployee *foo = (BNREmployee *)employees[i];
NSLog (@"%u", foo.employeeID);

#3

thanks for help