【发布时间】:2013-10-01 08:37:51
【问题描述】:
刚开始使用Objective C,所以请保持温和。我有一个类如下:
卡.h
#import <Foundation/Foundation.h>
@interface Card : NSObject
@property (nonatomic) NSUInteger x;
-(NSUInteger) getNum;
@end
卡.m
#import "Card.h"
@implementation Card
-(NSUInteger) getNum {
return self.x;
}
@end
main.c
#include <CoreFoundation/CoreFoundation.h>
#include "Card.h"
int main(int argc, const char * argv[])
{
return 0;
}
当我编译时,我得到了很多错误,第一个是:
NSObjCRuntime.h:解析问题:预期标识符或“(”。
我知道这很愚蠢 - 只是希望这里有人能发现我做错了什么。
【问题讨论】:
-
Objective-C 中的常见约定是 not 在 getter 前加上“get”,而是简单地将它们命名为要获取的属性。此外,拼写全名也是惯例。在您的情况下,
getNum将写为number。 -
感谢@David 的指点。我想约定很重要。在这种情况下,我纯粹是在创建一个测试方法,但我同意你的观点。
标签: objective-c