Possible Duplicate:
What’s the best way to put a c-struct in an NSArray?
I need to create an array of structures, such as:
typedef struct
{
int fill;
BOOL busy;
} MapCellST;
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?
Wrap the struct in an
NSValue
:To extract it later:
Use
NSMutableDictionary
rather thanNSMutableArray
.typedef struct {...} MyStruct;
Ya can't.
Only real Obj-C objects can be added directly to NSMutableArray and friends; in order to do what you are describing you would have to create a class with the properties of the struct you are wanting to use.
Edit: As Tamás says, you can also use an NSValue; but in all likelihood creating a class for your MapCell is a better idea.