This is a very basic question, so hopefully a solid answer is out there somewhere.
I've been working with Core Data for the past 3 weeks and finally have a nice chunk of code to handle 5 objects across 300 levels, broken down into 4 kinds of levels. Let's call these kinds of levels typeOfLevel (they are NSNumber's).
In short, my predicate for the fetch request says "if the combination of level X and type Y are not found, start setting certain objects". Well, what if I've already set typeOfLevel but my level object hasn't been set yet (because I've never actually played that level before)......I certainly don't want to keep setting typeOfLevel over and over again. So here's what I wrote:
if (![_levelInformation valueForKey:@"typeOfLevel"]) {
[_levelInformation setValue:typeNumber forKey:@"typeOfLevel"];
NSLog(@"Got here");
}
_levelInformation is my data model object (which I have tested, and is verified to contain values for the level and best move count (that I incorporate)). typeNumber is an NSNumber object that contains the value of what type of level I'm on. I also have verified the existence of this value through debugging.
My thought process is, if the argument in the if statement is false (if there is no value for the key typeOfLevel, then set one. This, in my mind, should only ever run once so long as my store hasn't been reset. This statement gets executed every single time I run this. typeOfLevel always gets set no matter what. Why is this? How can I make it only set itself once?
Aucun commentaire:
Enregistrer un commentaire