Using @property while using old methods in main



Although my program is running fine I do have a problem with something in the use of @property and @synthesize and then the use of setter methods setHeightInMeters and setWeightInKilos in the main.m file. since I deleted both setter methods from the Person class in both Person.h and Person.m how am I still being able to use them to set the value of this instances of heightInMeters and weightInKilos?


[code]#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[])

@autoreleasepool {
    // create an instance of Person
    Person *person = [[Person alloc] init];
    // Give the instance variable interesting values
    [person setHeightInMeters:1.8];   //the method setHeightInMeters was deleted from the Person class
    [person setWeightInKilos:96];      //the method setWeightInKilos was deleted from the Person class
    // Call the bodyMassIndex method
    float bmi = [person bodyMassIndex];
    NSLog(@"person (%d, %.2f) has a BMI of %.2f", [person weightInKilos], [person heightInMeters], bmi);
return 0;



[code]#import <Foundation/Foundation.h>

@interface Person : NSObject
// it has two instance variables
float heightInMeters;
int weightInKilos;
// You will be able to set those instance variables using these methodes
@property float heightInMeters; //setter & getter
@property int weightInKilos; //setter & getter
//This method calculates the Body MAss Index;

  • (float) bodyMassIndex;


[code]#import “Person.h”

@implementation Person

@synthesize heightInMeters, weightInKilos;

  • (float) bodyMassIndex {
    return weightInKilos / (heightInMeters*heightInMeters);



Because you have the property declarations (and the corresponding synthesize statements), the methods are automatically created for you but you can’t see them.


@ibex10 thank you