我目前在教自己Objective-C作爲第一語言。我明白所涉及的困難,但我卻是一個堅忍不拔的人。我已經開始在Apple Objective-C文檔上進行練習。我的目標是讓我的程序註銷我的名字和姓氏,而不是通用的Hello World問候語。Objective-C練習未聲明的標識符錯誤
我不斷收到使用未聲明的標識符錯誤。我試圖找出是什麼導致了錯誤。
這裏是introClass.h
#import <UIKit/UIKit.h>
@interface XYZperson : NSObject
@property NSString *firstName;
@property NSString *lastName;
@property NSDate *dateOfBirth;
- (void)sayHello;
- (void)saySomething:(NSString *)greeting;
+ (instancetype)person;
-(int)xYZPointer;
-(NSString *)fullName;
@end
這裏是IntroClass.m
#import "IntroClass.h"
@implementation XYZperson
-(NSString *)fullName
{
return[NSString stringWithFormat:@" %@ %@", self.firstName, self.lastName];
}
-(void)sayHello
{
[self saySomething:@"Hello %@", fullName]; //use of undeclared identifier "fullName"
};
-(void)saySomething:(NSString *)greeting
{
NSLog(@"%@", greeting);
}
+(instancetype)person{
return [[self alloc] init];
};
- (int)xYZPointer {
int someInteger;
if (someInteger != nil){
NSLog(@"its alive");
}
return someInteger;
};
@end
這將返回一個錯誤:有太多的參數的方法調用,預計1,2,有@ – TheM00s3
user3084800看看校正。 – dasblinkenlight
非常感謝,它工作!你能否解釋爲什麼SayHello方法只允許1個參數? – TheM00s3