Objective-c – Best way to store static reference arrays/dicts in Cocoa touch

cocoa-touchiphoneobjective c

I have several arrays of arrays or arrays of dicts that I would like to store in my iPhone app. This lists are static and won't be modified by the app or users. Occasionally they may be displayed but more likely they'll be iterated over and compared to some input value. Would the best way to store these arrays be a CoreData/SQLite data store, in a header file, or something I'm not thinking of? I could see making a class that only has these arrays stored in them for access, but I'm not sure if that's the best route to take.

Best Answer

I would do the following:

@implementation DataSource
+ (NSArray *)someData
{
  static NSArray *data = nil;
  if (!data) {
    data = [[NSArray arrayWithObjects:..., nil] retain];
  }
  return data;
}
@end

Additional arrays or arrays of dicts would be added as class methods on that class.

Related Topic