Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C-array as property in iOS

I am programming for iOS, and using ARC.

I am trying to use a c-array as property, but it reports error.

@property (strong, nonatomic)NSString *mappingTable[70][254];

The error is "Property cannot have array or function type NSString *[70][254]". How can I solve this problem? How can I declare c-array as property?

Note:
This is a two dimensional array, I think it is much easier to just use c-array, so I didn't use NSArray for it.

like image 526
nan Avatar asked Dec 21 '22 08:12

nan


1 Answers

Surprised this hasn't been suggested already but you can store the c-array in an NSData object. I just used this method to store an array of frames.

@property (nonatomic) NSData *framesArray;


// Create and initialize your c-style frames array
CGRect frames[numberOfFrames];
...
self.framesArray = [NSData dataWithBytes:frames length:(sizeof(CGRect) * numberOfFrames)];


// To Access the property
NSUInteger arraySize = [self.framesArray length] / sizeof(CGRect);
CGRect *frames = (CGRect *) [self.framesArray bytes];
like image 119
wfbarksdale Avatar answered Jan 04 '23 18:01

wfbarksdale