Я изучаю Objective-C. Я собираюсь создать простой класс, но при компиляции после ожидаемого результата я получаю эти ошибки.
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)
Вот это Employee.h
#import <Foundation/Foundation.h>
@interface Employee : NSObject
// properties
@property NSString *name;
@property NSDate *hireDate;
@property int employeeNumber;
-(void) someMethod;
@end
Вот это 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
Вот оно основное.м
#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;
}
Я на 10.6.8 с Xcode 4.2