我对 Objective-C 真的很陌生,当我练习书本练习时,我真的被困在这里。请帮我解决这个问题,我一直在思考可能导致此错误的原因超过三个小时。还是我没看懂!
最好的问候,拉吉。
提前致谢 !
主文件
#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 的大力帮助 :)