views:

33

answers:

1

I have 2 entities I want to link with KVO, one a single statTracker class that keeps track of different stats and the other an achievement class that contains information about achievements. Ideally what I want to be able to do is set up KVO by having an instance of the achievement class observe a value on the statTracker class and also set up a threshold value at which the achievement instance should be "triggered"(triggering in this case would mean showing a UIAlertView and changing a property on the achievement class.)

I'd like to also set these relationships up on instantiation of the achievement class if possible

so kind of like this:

Achievement *achievement1 = (Achievement *)[NSEntityDescription insertNewObjectForEntityForName:@"Achievement" inManagedObjectContext:[[CoreDataSingleton  sharedCoreDataSingleton] managedObjectContext]];
    [achievement1 setAchievementName:@"2 time launcher"];
    [achievement1 setAchievementDescription:@"So you've decided to come back for more eh? Here are some achievement points to get you going"];
    [achievement1 setAchievementPoints:[NSNumber numberWithInt:300];
            [achievement1 setObjectToObserve:@"statTrackerInstace"
                           propertyToObserve:@"timesLaunched" 
                           valueOfPropertToSatisfyAchievement:2]

Anyone out there know how I would set this up? Is there some way I could do this by way of relationships that I'm not seeing?

Thanks,

Nick

A: 

NSManagedObjects are NSObjects, if you back them with classes you can add any methods that you'd like.

That said, you may want to create an achievement manager class that manages the relationships between the classes and executes any trigger responses.

jessecurry
yeah that is how i originally started this thing (with the achievement tracker class) and I'm thinking about trying not to do it that way. but maybe you're right there might not be a way around it, or at least not a way that is easier than just doing it with a achievement tracker. --thanks for the quick response.
nickthedude