你如何为数组设置@synthesize?

时间:2009-04-07 20:33:46

标签: iphone objective-c macos

如何为以下数组设置@synthesize:float rgb [3]。另外,是@property行:@property(nonatomic,assign)float rgb ??感谢

1 个答案:

答案 0 :(得分:3)

如果您希望将其用作属性,我不相信您可以在界面中定义数组大小。你需要做一些事情:(原谅任何语法错误,这是来自记忆)

@interface MyClass : NSObject {
    float *rgb;
}

@propery (nonatomic, assign) float *rgb;

然后在您的实施中:

@implementation MyClass

@synthesize rgb;

@end

然后你必须使用一些C函数初始化指针,例如:

rgb = (float *)malloc(sizeof(float) * 3);