从 NSMutableArray 添加和提取结构 [英] Add and extract struct from NSMutableArray

查看:55
本文介绍了从 NSMutableArray 添加和提取结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
放置 c-struct 的最佳方法是什么在 NSArray 中?

我需要创建一个结构数组,例如:

I need to create an array of structures, such as:

typedef struct
{
    int fill;
    BOOL busy;
} MapCellST;

如何在 NSMutableArray 中添加此结构的实例,以及如何提取该结构的副本并在以后使用其属性?

How can I add instances of this structure in NSMutableArray and how I can extract copies of the structure and work with its properties later?

推荐答案

将结构包裹在 NSValue 中:

MapCellSt x;
NSValue* value = [NSValue value:&x withObjCType:@encode(MapCellSt)];

稍后提取:

[value getValue:&x];

这篇关于从 NSMutableArray 添加和提取结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆