목표 C newbie이 (가) 있습니다. 내 int main이 아래에 있습니다. 질문 :이 악명 높은 오류 메시지가 나타나는 이유는 무엇입니까? "생존력 없음 @interface person의 경우 selector firstName을 선언합니다."사람에 대한 가시성 @interface가 없습니다
.m 파일의 이름은 firstName, lastName입니다.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Person.h"
int main(int argc, char *argv[])
{
Person *ben = [[Person alloc] init];
[email protected]"Ben";
NSLog(@"--->%@",ben.firstName); //output ---->Ben
[ben firstName:"Ben"]; //RED ERR: no visibility @interface for Person
}
.H
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *firstName;
NSString *lastName;
}
@property (nonatomic, copy) NSString *firstName;
@property (nonatomic, copy) NSString *lastName;
- (NSString *) fullName;
-(void) sayHello;
@end
하는 .m
#import "Person.h"
@implementation Person
@synthesize firstName, lastName;
-(void) sayHello
{
NSLog(@"Hello");
}
- (NSString *) fullName
{
return [NSString stringWithFormat:@"%@ %@", [self firstName], [self lastName]];
}
@end
"Foundation.h"에서 가져 오기 때문에 "NSObject.h"또는 "NSString.h"를 가져올 필요가 없습니다. – Macro206
알 것. 감사! – adhg