目标 C 新手在这里:我的 int main 在下面。问题:为什么我会收到这条臭名昭著的错误消息:“No viability @interface for person 声明选择器 firstName”
.m 文件有@synthesize firstName, lastName;
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Person.h"
int main(int argc, char *argv[])
{
Person *ben = [[Person alloc] init];
ben.firstName=@"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
他们
#import "Person.h"
@implementation Person
@synthesize firstName, lastName;
-(void) sayHello
{
NSLog(@"Hello");
}
- (NSString *) fullName
{
return [NSString stringWithFormat:@"%@ %@", [self firstName], [self lastName]];
}
@end