I am beginning to delve into iOS development, and am learning Objective C. My background is Java.
I'm attempting to create a simple console game, and have created the following constants:
#import <Foundation/Foundation.h>
static const NSString *ROCK = @"Rock";
static const NSString *PAPER = @"Paper";
static const NSString *SCISSORS = @"Scissors";
static const NSString *LIZZARD = @"Lizzard";
static const NSString *SPOCK = @"Spock";
static const NSArray *WEAPONS = @[SPOCK, ROCK, SCISSORS, LIZZARD, PAPER];
The trouble is that I get an error on the last line: Initializer element is not a compile-time constant
.
I tried to figure out what this means -- the closest thing I could find was this question by Fred Collins, where he notes that "This happens because objects works [sic] at runtime." I'm still not entirely sure what the implication of this is -- how is this different from Java? (I can definitely do this in Java!)
Regardless, I need some way of initializing NSArray *WEAPONS
, and I can't make the answers to Fred Collin's question work for me without adding another file. (He is using a class for his constants, where as my program is simple enough to be contained in the same file as the main method.)