Objective-C static inline NSString array

Georges Oates Larsen picture Georges Oates Larsen · May 4, 2012 · Viewed 8k times · Source

Hi :) I am trying to create a static C-Array of NSStrings.

This is what I tried:

static NSString** polygonNames = {@"Radical Isotope", @"Point", @"Line", @"Triangle", @"Square", @"Pentagon", @"Hextagon", @"Heptagon", @"Octagon", @"Nonagon", @"Decagon", @"Hendecagon", @"Dodecagon",  @"Tridecagon",  @"Tetradecagon",  @"Pentadecagon",  @"Hexadecagon",  @"Heptadecagon", @"Octadecagon", @"Enneadecagon"};

No compiler errors, but I am getting 41 warnings, all of which are one of the three following:

"warning: initialization from incompatible pointer type"
"warning: excess elements in scalar initializer"
"warning: (near initialization for 'polygonNames')"

Which leads me to believe when I use this class, I am going to be presented with plenty of sigbarts or some other memory access error...

What is the proper way to initialize a static array of NSStrings (preferably inline, and I would like to use C-arrays, not NSArrays)?

Answer

Richard J. Ross III picture Richard J. Ross III · May 4, 2012

Try this:

static NSString *polygonNames[] = { @"Radical Isotope", @"Point", @"Line", /* etc */ };