开发者

iPhone OS: Is there a way to set up KVO between two ManagedObject Entities?

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 statTrack开发者_如何转开发er 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜