我對Objective-C非常陌生,當我練習書本練習時,我真的被困在這裏,請幫我解決這個問題。我一直在想,是什麼引發這個錯誤了三個多小時。我仍然沒有得到它!Objective-C錯誤「XYZPerson沒有可見的@interface」聲明選擇器'saySomething'
最好的問候, 拉吉。
提前感謝!
的main.m
#import <Foundation/Foundation.h>
#import "XYZPerson.h"
#import "XYZShout.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
//XYZPerson *some = [[XYZPerson alloc]init];
XYZShout *some = [[XYZShout alloc]init];
[some sayHello];
// insert code here...
// NSLog(@"Hello, World!");
}
return 0;
}
XYZPerson.h
#import <Foundation/Foundation.h>
@interface XYZPerson : NSObject
@property NSString *firstName;
@property NSString *secondName;
@property NSDate *dob;
-(void) saySomething;
-(void) sayHello;
@end
XYZPerson.m
#import "XYZPerson.h"
@implementation XYZPerson
-(void) sayHello {
[self saySomething:@"Hello all"];
}
-(void) saySomething:(NSString *)greet {
NSLog(@"%@", greet);
}
@end
XYZShout.h
#import "XYZPerson.h"
@interface XYZShout : XYZPerson
// -(void) saySomething;
@end
XYZShout.m
#import "XYZShout.h"
@implementation XYZShout
-(void) saySomething:(NSString *)greet {
NSString *upperGreet = [greet uppercaseString];
[super saySomething:upperGreet]; // this is where I get the error mentioned above
}
@end
得到它的工作!感謝@MatthewD,@trojanfoe,@ JFS對你的大力幫助:)
您是否也可以包含XYZShout.h的代碼? – MatthewD 2013-02-19 11:27:04
如果將XYZPerson.h中的' - (void)saySomething'改爲' - (void)saySomething:greet;'? – MatthewD 2013-02-19 11:29:39
添加XYZShout.h馬修 – Raj0689 2013-02-19 11:38:34