




















#import <Foundation/Foundation.h>
#import "BNRPerson.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// create an intance of BNRPerson
BNRPerson *mikey = [[BNRPerson alloc]init];
// give the instance variables interesting values using setters
[mikey setHeightInMeters:1.8];
[mikey setWeightInKilos:96];
// log the instance variables using the getters
float mikeyHeight = [mikey heightInMeters];
int mikeyWeight = [mikey weightInKilos];
NSLog(@"mikey is %.2f meters tall and weighs %d kilograms", mikeyHeight, mikeyWeight);
// log some values using custom methods;
float mikeyBMI = [mikey bodyMassIndex];
NSLog(@"mikey has a BMI of %f", mikeyBMI);
}
return 0;
}


Another attribute that you will see shortly is copy
. Practically speaking, whenever you declare a property that points to an NSString
or an NSArray
, you should include the copy attribute
















网友评论