我一直收到错误的“预期”;'声明结束时“

时间:2013-08-15 01:30:31

标签: objective-c

@implementation Fruit{
-(void) setWeight: (int)a{
    weight=a;
}
-(void) setType:t{
    Type=t;
}
-(void) setName:n{
    name=n;
}

错误出现在第二行。我尝试了显示隐形空间技巧,它没有用。

2 个答案:

答案 0 :(得分:6)

您的实施旁边有一个空心括号{,请将其删除,并确保您的文件以@end结尾

编辑:其他问题是

  1. 你写错了你的二传手。您需要为类型和名称提供类似于setWeight int的类型。

  2. 如果您打算制作自己的制定者,则需要_type = t和_name = n

  3. 我刚刚编写了这段代码并且构建没有问题:

    @interface Fruit : NSObject
    @property (nonatomic) int weight;
    @property (nonatomic, strong) NSString *type;
    @property (nonatomic, strong) NSString *name;
    @end
    
    
    #import "Fruit.h"
    
    @implementation Fruit
    -(void) setWeight: (int)a{
        _weight=a;
    }
    -(void) setType:(NSString *)t{
        _type=t;
    }
    -(void) setName:(NSString *)n{
        _name=n;
    }
    
    @end
    

答案 1 :(得分:1)

@implementation周围不需要括号。相反,你只需要在它之后放一个@end

@implementation Fruit
...
@end
相关问题