【发布时间】:2014-02-21 20:39:30
【问题描述】:
我目前正在自学将 Objective-C 作为第一语言。我理解其中的困难,但我是一个坚持不懈的人。我已经开始在 Apple Objective-C 文档上做练习了。我的目标是让我的程序注销我的名字和姓氏,而不是通用的 Hello World 问候语。
我不断收到“使用未声明的标识符”错误。我试图找出导致错误的原因。
这是 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
【问题讨论】:
标签: ios objective-c object-code