目标C中的不完整实施警告

时间:2013-02-22 21:10:14

标签: ios objective-c object

我看过其他帖子,但我不确定他们在谈论什么。我刚开始使用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;
}

3 个答案:

答案 0 :(得分:2)

在Xcode中,在左侧边栏的警告标签中找到警告(它是左边的第4个图标,看起来像/!\),然后点击旁边的小三角形。它将列出所有缺失的方法。

答案 1 :(得分:1)

您需要在@interface@implementation中拼写相同的方法。您似乎忘记了e

中的setWeight:
 -(void) setWight: (int) w;  //same as  void setWeight(int a);

编译器警告你,因为根据@interface声明中的这个拼写错误,它希望你实现一个名为setWight:的方法,但你已经实现了setWeight:

答案 2 :(得分:0)

您的接口要么具有接口中定义的方法,这些方法在实现中不存在,要么您的接口已声明它实现了协议,该协议具有所需的方法,并且您尚未在实现文件中实现它们。

相关问题