Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C static inline NSString array

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)?

like image 630
Georges Oates Larsen Avatar asked May 04 '12 00:05

Georges Oates Larsen


1 Answers

Try this:

static NSString *polygonNames[] = { @"Radical Isotope", @"Point", @"Line", /* etc */ };
like image 120
Richard J. Ross III Avatar answered Sep 19 '22 13:09

Richard J. Ross III