我看过其他帖子,但我不确定他们在说什么。我刚开始 Xcode,它对我来说是新的。警告只是说“语义问题不完整的实现”
#import <Foundation/Foundation.h>
#import "classOne.h"
@implementation classOne <------ this is where I get the Warning
-(void) print
{
NSLog(@"I am %i years old, and weigh %i lbs.", age, weight);
}
-(void) setAge:(int) a
{
age = a;
}
-(void) setWeight: (int) w
{
weight = w;
}
@end
那么.h文件如下:
#import <Foundation/Foundation.h>
@interface classOne : NSObject {
int age;
int weight;
} //Person: NSObject
-(void) print;
-(void) setAge: (int) a; //same as void setAge(int a);
-(void) setWight: (int) w; //same as void setWeight(int a);
@end
主文件如下:
#import <Foundation/Foundation.h>
#import "classOne.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
classOne *Trenton;
Trenton = [classOne alloc]; //reserves memory for the object Trenton
Trenton = [Trenton init]; //initalizes the object
[Trenton setAge: 25];
[Trenton setWight: 230];
[Trenton print];
//[Trenton release]; //release frees any memory we borrowed from alloc
}
return 0;
}