Property not found on Object type "BNREmployee"


#1

Hey everyone, hope everyone is having a good week!

so I have been tackling chapter 21 without too many problems until the very end, just before the challenge. I get the error: Property ‘weightInKilos’ not found on Object Type “BNREmployee”. I went back to the inheritance chapter, and I just cannot find the issue.

Edit: I keep trying to find the issue, it seems like BNREmployee isn’t linked,or a subclass of BNRPerson, but when I look at my code it seems like BNREmployee IS a subclass of BNRPerson.

Here is my code:

BNR Employee.h

[code]#import “BNRPerson.h”
//link BNRAsset to BNREmployee.

@class BNRAsset;

@interface BNREmployee:BNRPerson

//here we create our a new instance variable to contain a pointer to the mutable array that we will create.And a couple of new methods.

{
NSMutableArray *_assets;
}

@property(nonatomic)int employeeId;
@property(nonatomic)int officeAlarmCode;
@property(nonatomic)NSDate *hiredate;

//here is our instance variable that contain the pointer
@property(nonatomic,copy) NSArray *assets;

-(double)yearsOfEmployment;

// and here are our new methods

//this one is to add an asset to the array

  • (void)addAssets:(BNRAsset *)a;

//this one is to sum up the resale value of assets
-(unsigned int)valueOfAssets;

@end[/code]

BNREmployee.m

[code]#import “BNREmployee.h”

//here we need to import our new class to access it
#import “BNRAsset.h”

@implementation BNREmployee

//accessors for assets properties

-(void)setAssets:(NSArray *)a
{
_assets=[a mutableCopy];
}

-(NSArray *)assets
{
return [_assets copy];
}

-(void)addAssets:(BNRAsset *)a
{
//is asset nil?

if(!_assets){
    //create a array
    _assets=[[NSMutableArray alloc]init];
}
[_assets addObject:a];

}

  • (unsigned int)valueOfAssets
    {
    //Sum up the resale value of assets
    unsigned int sum=0;
    for(BNRAsset *a in _assets){
    sum+=[a resaleValue];
    }
    return sum;
    }

//description of the employee’s assets.
-(NSString *)description
{
return [NSString stringWithFormat:@"<Employee %d: $%d in assets>", self.employeeId,self.valueOfAssets];
}

//method to announce when deallocating memory
-(void)dealloc
{
NSLog(@“deallocating %@”, self);
}

-(double)yearsOfEmployment
{
//do I have a non-null hire date?

if(self.hiredate){
    NSDate*now=[NSDate date];
    NSTimeInterval secs=[now timeIntervalSinceDate:self.hiredate];
    return secs/31557600.0;
}else{
    return 0;
}

}

@end
[/code]

BNRPerson.h

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

@interface BNRPerson : NSObject

@property(nonatomic) float heightInMeters;
@property(nonatomic) int weightInKilos;

//BNRPerson method tp calculate BMI

  • (float)bodyMassIndex;

@end
[/code]

BNRPerson.m

[code]#import “BNRPerson.h”

@implementation BNRPerson

  • (float)bodyMassIndex
    {
    return _weightInKilos / (_heightInMeters*_heightInMeters);
    }
    @end[/code]

and my Main since I doubt it has anything to do with BNRAsset right?

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

#import “BNREmployee.h”
#import “BNRAsset.h”

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

@autoreleasepool {

//create an array of BNREmployee Objects

    NSMutableArray *employees=[[NSMutableArray alloc]init];
    
    for(int i=0;i<10;i++){
        //create an instance of BNREmployee
        BNREmployee *mikey= [[BNREmployee alloc]init];
        
        //Give the instance varialble (mikey's variables) interesting values
        
        mikey.weightInKilos=90+i;
    }
    
    
    
    
}
return 0;

}
[/code]

Thanks for the help everyone, and by the way the book is amazing!

Charles


#2

I noticed the others have spaces. Maybe give that a try.

@interface BNRPerson : NSObject,
@interface BNREmployee : BNRPerson


#3

I’ll be sure to try that out when I get home,thanks for taking the time to read it and I will get back to you!

Charles


#4

I noticed the <Foundation/Foundation.h> is missing. Not sure if that is the problem or not. Just copy this into your BNREmployee header and should be good to go. Have a good one

#import <Foundation/Foundation.h>
#import "BNRPerson.h"
@class BNRAsset;
@interface BNREmployee : BNRPerson

#5

Tried both solutions and thanks a lot for helping but I still have the same error, "Semantic Issue: Property ‘weightInKilos’ not found on object of type ‘BNREmployee *’


#6

Sorry to hear. Try pressing these buttons together on your keyboard SHIFT + COMMAND + K. You should see “Clean Succeeded”. Let me know if that helps. Where you getting that – in main?


#7

Yes it is in main, and Ill will be trying this as soon as I get home and post results. Again I cant thank you enough for helping me out!


#8

Try deleting that line @property(nonatomic) int weightInKilos; and then retype it back in. Make sure there is a space between property and (nonatomic). Then do the clean command again. What about the other property heightInMeters? Does that one appear to be working? What version of xcode are you using? Maybe there is a bug in xcode and needs updating? Your welcome… no problem.


#9

So I did Clean it and it succeeded. I retyped the @property… line and I am getting the same error. I just can’t find the issue I dont get it!


#10

Put this synthesize command in your BNRPerson.m file right after the @implementation

#import “BNRPerson.h”
@implementation BNRPerson


#11

Put the synthesize code in main.m as well.