Question

I'm learning Objective-C. I'm at the point of creating a simple class but when compiling, after the expected result, I get this errors.

2014-05-08 10:15:47.998 ClassCreation[978:903] This is a method call in the new object!
2014-05-08 10:15:48.007 ClassCreation[978:903] -[Employee setName:]: unrecognized selector sent to instance 0x10010c850
...
terminate called after throwing an instance of 'NSException'
(gdb) 

Here it is the Employee.h

#import <Foundation/Foundation.h>
@interface Employee : NSObject

// properties
@property NSString *name;
@property NSDate *hireDate;
@property int employeeNumber;

-(void) someMethod;

@end

Here it is the Employee.m

#import "Employee.h"

@implementation Employee

// matching the method definition that is defined in the interface
-(void) someMethod {
NSLog(@"This is a method call in the new object!");
}

@end

Here it is the main.m

#import <Foundation/Foundation.h>
#import "Employee.h"

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

@autoreleasepool {

    //  inside here, I instantiate a new object of my new employee class
    Employee *fred = [[Employee alloc] init];

    // call a method of our new object
    [fred someMethod];

    // change a property of new object
    [fred setName:@"Fred Smith"];

}
return 0;
}

I'm on 10.6.8 with Xcode 4.2

Was it helpful?

Solution

With XCode 4.2 you need to add the line

@synthesize name,hireDate,employeeNumber;

to your Employee.m file after the @implementation line

Auto synthesis of properties only became available with XCode 4.4 - http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html

You should look at upgrading your XCode version

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top