Book doesn't state need for @synthesize


#1

I have followed the code in the book to initially create the Person object but I received an error that Receiver type Person for instance message does not declare a method with selector ‘setWeightinKilos’. Do I need to use @synthesize for my declaration? If so the book doesn’t include that in the book.

#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 variables intersting values
        [person setWeightInKilos:96];
        [person setHeightInMeters:1.8];
        
        // Call the bodyMassIndex method
        float bmi = [person bodyMassIndex];
        NSLog(@"person has a BMI pf %f", bmi);
                
    }
    return 0;
}

#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 methods
- (void)setHeightInMeters:(float)h;
- (void)setWeightInKilos;

//This method calculates the Body Mass Index
- (float)bodyMassIndex;


@end
#import "Person.h"

@implementation Person


- (void) setHeightInMeters:(float)h
{
    heightInMeters = h;
}
- (void) setWeightInKilos:(int)w
{
    weightInKilos = w;
}
-(float)bodyMassIndex
{
    return weightInKilos / (heightInMeters * heightInMeters);
}


@end

#2

In Person.h,

- (void)setWeightInKilos;
should be


#3

That worked, thanks!