iphone - 如何在 obj-c 上合成 C 数组的 getter 和 setter

标签 iphone objective-c cocoa

我有一个 ObjC 对象定义如下

@interface Fruit : NSObject
{
    int fruitsinbranch[4];
}
@property (readonly) int fruitsinbranch[4];
@end

然后在实现中我有通常的

@synthesize fruitsinbranch[4];

它不起作用。正确的做法是什么?

(不,我不是在要求其他方法来做事,比如 NSArray 等......我想要我提出的问题的答案)。

更新:我的解决方案很蹩脚,但它有效。我创建了该方法

-(int) fruitsinbranch:(int) i

这提供了一个足够接近我想要的解决方案。

最佳答案

您可以获得的最接近的结果是使用 int* 属性而不合成 getter:

 @interface Fruit : NSObject {
     int fruitsinbranch[4];
 }
 @property (readonly) int* fruitsinbranch;
 - (int *)fruitsinbranch { return fruitsinbranch; }

关于iphone - 如何在 obj-c 上合成 C 数组的 getter 和 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3233617/

相关文章:

iphone - 写入文件而不覆盖 ObjC

objective-c - Cocoa - 复制邮件按钮栏

objective-c - 使用 [[NSRunLoop currentRunLoop] runUntilDate :[NSDate date]] to let the scheduled selectors fire

objective-c - 使用 Cocoa 检测正在运行的应用程序何时播放音频

iphone - 提交的 iPhone 应用程序二进制详细信息中存在 "Prerendered Icon Flag: true",但图标在商店中显示为光泽效果

iphone - project.pbxproj 中的 subversion 冲突正常吗?

ios - plist 条目的编译时错误

ios - Swizzling 不适用于类方法

swift - 在 cocoa 后台连续运行代码

cocoa - NSPredicateEditorRowTemplate : how to to populate right side popup