The code to check out what objects are deallocating is giving me fits. i have copied the code straight from the book but i still get an error.
on the line [randomEmployee addAsset:asset];
i line i get the error " no visiblie @interface for 'BNREmployee declares the selector ‘addAsset:’
what the heck did i do wrong. thanks
ps. im runnig xcode 6.1 on yosemite. thanks
here is is the code
//
// BNREmployee.h
// BMITime
//
// Created by Tevin Harris on 10/23/14.
// Copyright (c) 2014 Tevin Harris. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "BNRPerson.h"
@class BNRAsset;
@interface BNREmployee : BNRPerson
@property (nonatomic) unsigned int employeeID;
@property (nonatomic) NSDate *hireDate;
@property (nonatomic, copy) NSArray *assets;
- (double)yearsOfEmployment;
- (void)addAsset:(BNRAsset *)a;
- (unsigned int)valueOfAssets;
@end
BNREmployee.m
[code]//
// BNREmployee.m
// BMITime
//
// Created by Tevin Harris on 10/23/14.
// Copyright © 2014 Tevin Harris. All rights reserved.
//
#import “BNREmployee.h”
#import “BNRAsset.h”
//class exension
@interface BNREmployee ()
{
NSMutableArray *_assets;
}
@property(nonatomic) unsigned int officeAlarmCode;
@end
@implementation BNREmployee
// Accessors for assets properties
-
(void)setAssets:(NSArray *)a
{
_assets = [a mutableCopy];
} -
(NSArray *)assets
{
return [_assets copy];
} -
(void)addAsset:(BNRAsset *)a
{
// Is assets nil?
if (!_assets) {// Create the array _assets = [[NSMutableArray alloc] init];
}
[_assets addObject:a];
} -
(unsigned int)valueOfAssets
{
// Sum up the resale value of the assets
unsigned int sum = 0;
for (BNRAsset *a in _assets) {
sum += [a resaleValue];
}
return sum;
} -
(double)yearsOfEmployment
{
//do i have a non-nil hire date?
if (self.hireDate) {//NSTimeInterval is the same as double NSDate * now = [NSDate date]; NSTimeInterval secs = [now timeIntervalSinceDate:self.hireDate]; return secs / 31557600.0; //seconds per year
} else{
return 0;}
}
// - (float)bodyMassIndex
//{
// float normalBMI = [super bodyMassIndex];
// return normalBMI * .9;
//} -
(NSString *)description
{
// return [NSString stringWithFormat:@"<Employee %d>", self.employeeID];
return [NSString stringWithFormat:@"<Employee %u: %u in assets>", self.employeeID, self.valueOfAssets];
} -
(void)dealloc
{
NSLog(@“deallocating %@”, self);
}
@end
[/code]
main.m
[code]//
// main.m
// BMITime
//
// Created by Tevin Harris on 10/23/14.
// Copyright © 2014 Tevin Harris. All rights reserved.
//
#import <Foundation/Foundation.h>
#import “BNREmployee.h”
#import “BNRAsset.h”
int main(int argc, const char * argv[]) {
@autoreleasepool {
/*
//give the instance variables interesting values using setters
[mikey setWeightInKilos:96];
[mikey setHeightInMeters:1.8];
//log the instance variables using the getters
float height = [mikey heightInMeters];
int weight = [mikey weightInKilos];
//create an instance of BNREmployee
BNREmployee * mikey = [[BNREmployee alloc] init];
//give properties intersting values
mikey.weightInKilos = 96;
mikey.heightInMeters = 1.8;
mikey.employeeID = 12;
mikey.hireDate = [NSDate dateWithNaturalLanguageString:@"Aug 2nd, 2010"];
//log the instance variables using the getters
float height = mikey.heightInMeters;
int weight = mikey.weightInKilos;
NSLog(@" mikey is %.2f meters tall and weighs %d kilos", height, weight);
NSDate * date = mikey.hireDate;
NSLog(@"%@ hired on %@", mikey, date);
NSLog(@"Employee %u hired on %@", mikey.employeeID, mikey.hireDate);
//log some vales using custom methods
float bmi = [mikey bodyMassIndex];
double years = [mikey yearsOfEmployment];
NSLog(@"BMI of %.2f has worked with us for %.2f years", bmi,years);
*/
// 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 variables interesting values
mikey.weightInKilos = 90 + i;
mikey.heightInMeters = 1.8 - i/10.0;
mikey.employeeID = i;
// Put the employee in the employees array
[employees addObject:mikey];
}
// Create 10 assets
for (int i = 0; i < 10; i++) {
// Create an asset
BNRAsset *asset = [[BNRAsset alloc] init];
// Give it an interesting label
NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d", i];
asset.label = currentLabel;
asset.resaleValue = 350 + i * 17;
// Get a random number between 0 and 9 inclusive
NSUInteger randomIndex = random() % [employees count];
// Find that employee
BNREmployee *randomEmployee = [employees objectAtIndex:randomIndex];
// Assign the asset to the employee
[randomEmployee addAsset:asset]; <--this line gives me a error " no visiblie @interface for 'BNREmployee declares the selector 'addAsset:'
}
NSLog(@"Employees: %@", employees);
NSLog(@"Giving up ownership of one employee");
[employees removeObjectAtIndex:5];
NSLog(@"Giving up ownership of arrays");
employees = nil;
}
return 0;
}
[/code]