我目前正在自学Objective-C作为第一语言。我理解其中的困难,但我是一个坚持不懈的人。我已经开始在 Apple Objective-C 文档上做练习了。我的目标是让我的程序注销我的名字和姓氏,而不是通用的 Hello World 问候语。
我不断收到 Use of Undeclared identifier 错误。我试图找出导致错误的原因。
这是 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