I have a set of legacy multi-dimenstional arrays of a struct SpaceData; the following is a typical one, and some are larger.
SpaceData dataArray[2][4] ={
{ {16, 0, false}, {6, -2, true}, {9, -1, true}, {9, 0, true} },
{ {1, 0, false}, {8, -2, true}, {0, -1, true}, {0, 0, true} },
}
I want to use these to initialize Objective C objects with these data sets. So I'm creating a SpaceDataClass but have no idea how to "feed" these into the objects. I am dreading looping through these or in anyway copying the data over.
Is there an easier way of just have the objects property point to these already existing data structures?
Thanks for your help.
If you want SpaceData
to be an Objective-C object and you want to store these objects in a multi-dimensional NSArray
then there's no getting around having to initialize three NSArray
instances and 8 SpaceData
instances (according to your example):
NSArray* dataArray = @[
@[ [SpaceData dataWithX:16 Y:0 active:NO], [SpaceData dataWithX:9 Y:-2 active:YES], [SpaceData dataWithX:9 Y:-1 active:YES], [SpaceData dataWithX:9 Y:0 active:NO] ],
@[ [SpaceData dataWithX:1 Y:0 active:NO], [SpaceData dataWithX:8 Y:-2 active:YES], [SpaceData dataWithX:0 Y:-1 active:YES], [SpaceData dataWithX:0 Y:0 active:YES] ]
];
However, Objective-C is just a layer on top of plain old C and there's nothing stopping you from doing "C" stuff in your "Objective-C" code. You can continue to use plain old C-structs to hold this kind of data if it suits your needs. AppKit, UIKit, and Foundation use plain old C structs in many places (CGRect, CGPoint, NSRange, to name but three).