objective-c - 从另一个类调用 float 组

标签 objective-c ios arrays class

菜鸟问题在这里。

如果我有一个带有数组 float itemsPosition[20][20] 的 A 类,并且我有另一个 B 类来访问它,我该怎么做?

我通常这样做是为了分配 A 类并访问其他对象,但在这种情况下,我无法在 A 类中合成 float 组。

有什么想法吗?

最佳答案

您可以@synthesize一个NSValue来保存指向数组的指针。

@interface SomeObject : NSObject
@property (strong, nonatomic) NSValue *itemsPosition;
@end

@implementation SomeObject
@synthesize itemsPosition;
...
static float anArray[20][20];
...
- (void) someMethod
{
    ... add items to the array
    [self setItemsPosition:[NSValue valueWithPointer:anArray]];
}
@end

@implementation SomeOtherObject
...
- (void) someOtherMethod
{
    SomeObject *obj = [[SomeObject alloc] init];
    ...
    float (*ary2)[20] = (float(*)[20])[obj.itemsPosition pointerValue];
    ...
}

关于objective-c - 从另一个类调用 float 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667318/

相关文章:

java - 合并排序跟踪说明

c++ - 如何正确显示一个二维字符串数组?

ios - Kontakt 信标和 iOS : didStartMonitoringForRegion not working as expected

ios - 如何在支持 iOS 6 的情况下获得类似于 iOS 7 主屏幕的视差运动偏移?

javascript - iOS WKWebView 选项选择触发太迟

ios - iOS 中的本地通知

python - 迭代多维数组并跟踪/执行迭代索引操作的最佳方法是什么

objective-c - 构建 iOS 应用程序后退出代码 1 错误

objective-c - 如何在 NSOutlineView 中设置本地化的显示/隐藏按钮

ios - 何时创建自定义数据源方法而不是设置变量