Hi gang,
I thought I had this sorted, but I am still missing something.
Very simply, I have a Settings class that hold a DAO (sitting on a plist). I want to have a couple of enums for the settings for convenience and readability, such as GamePlayType and DifficultyLevel. Right now I am defining them in the Settings.h file above the @interface line as such:
typedef enum {
EASY,
NORMAL,
HARD
} DifficultyLevel;
and
typedef enum {
SET_NUMBER_OF_MOVES,
TO_COMPLETION
} GamePlayType;
If I access them from within the Settings class like:
- (int)gridSizeForLOD {
switch ([self difficultyLevel]) {
case EASY:
return GRID_SIZE_EASY;
case NORMAL:
return GRID_SIZE_NORMAL;
case HARD:
return GRID_SIZE_HARD;
default:
return GRID_SIZE_NORMAL;
}
}
everything is fine.
But, if I try to access them outside of the Settings class, let's say in my main view controller class, like this:
if (([settings gameType] == SET_NUMBER_OF_MOVES) && (numMoves == [settings numMovesForLOD])) {
[self showLoseScreen];
}
I get errors (like EXC_BAD_ACCESS) or the condition always fails. Am I doing something incorrectly?
Also, I should point out that I have this code for the call to gameType (which lives in the Settings class):
- (GamePlayType)gameType {
return [dao gameType];
}
and the DAO implements gameType like this:
- (int)gameType {
return (settingsContent != nil) ? [[settingsContent objectForKey:@"Game Type"] intValue] : 0;
}
I know I have the DAO returning an int instead of a GamePlayType, but A) the problem I am describing arose there when I tried to use the "proper" data type, and B) I did not think it would matter since the enum is just a bunch of named ints, right?
Any help, greatly appreciated. I really want to understand this thoroughly, and something is eluding me...
Cheers,
Chris