Having some trouble getting BMITime code to run


#1

I’ve been working through the book with no massive issues so far but for some reason i’m getting a lot of errors when trying to use the BNREmployee class.
This is what is in my main.m:

[code]#import <Foundation/Foundation.h>
#import “BNREmployee.h”
#import “BNRPerson.h”

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

@autoreleasepool {
 
    // create and instance of BNREmployee
    BNREmployee *dan = [[BNREmployee alloc] init];
    

    //give the instance variables interesting values using setters
    dan.weightInKilos = 100;
    dan.heightInMeters =1.75;
    dan.employeeID = 12;
    dan.hireDate = [NSDate dateWithNaturalLanguageString:@"Feb 27th, 2014"];
    
    
    //log the instance vars with the getters
    float height = dan.heightInMeters;
    int weight = dan.weightInKilos;
    NSLog(@"I am %.2f meters tall and weigh %d kilos.\n", height, weight);
    //log some values using custom methods
    float bmi = [dan bodyMassIndex];
    NSLog(@"This fat fuck has a BMI of %f", bmi);
    
    
    
}
return 0;

}[/code]

I get errors saying “Property ‘weightInKilos’ is not found on object type BNREmployee *”. I get a similar error for every setter an getter in the code.
If I change BNREmployee *dan = [[BNREmployee alloc]init]; to BNRPerson *dan = [[BNREmployee alloc]init]; those errors disappear for the height and weight methods but are still there for the employee methods.

Is there something that i’m missing here? I assumed that with inheritance I would just be able to call methods from a superclass with no issue, and i’m sure thats what is meant to happen.


#2

What do the header files themselves look like?

Are you sure you made BNREmployee a subclass of BNRPerson?


#3

Hi, it appears you didnt declare the @property for weightInKilos and heightInMeters in the Person.h file.
Try that, then you can declare self.heightInMeters = 1.8; etc


#4

Just had the same error and just couldn’t figure it out. The @property had been declared as it should and everything seemed to be ok.

Turns out that it was due to me having created two different versions of BNREmployee.h / BNREmployee.m in different subfolders. Removing it from the side panel didn’t actually delete it from the folder, so it didn’t know which version to use (as one did not have the @property declared). I removed the duplicate files and it began working.