• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to make KVO's 'addObserver' survive program restart?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to make KVO's 'addObserver' survive program restart?


  • Subject: How to make KVO's 'addObserver' survive program restart?
  • From: "Arthur C." <email@hidden>
  • Date: Tue, 01 Aug 2006 19:23:31 +0200

(was: How to make KVO setup persistent?)

I have two Core Data entities (say Person, Age), each with 0 instances to start with. In the program, I create n instances of Person, which creates n instances of Age. KVO is set up by:

@interface Person
{
  Age * myAge;
}

@implementation Person
- (void) awakeFromInsert
{
// fragment
	[self setAge: [NSEntityDescription insertNewObjectForEntityForName:
@"Age" inManagedObjectContext: managedObjectContext]];

[self addObserver:myAge forKeyPath:@"yearofbirth"
options:NSKeyValueObservingOptionNew context:nil];
}

So far, so good. But when the application is quit and relaunched, the KVO setup is lost. What I'm trying to achieve is to set it up again in awakeFromFetch.

I have a solution which is (still) working, and with the most important memory issues of the previous version fixed.
I now use accessor methods to set/get an instance variable 'myAge' in the Person object.


-(void) awakeFromFetch
{
// first, fetch the 'Age' object with index equal to [self index] using NSFetchRequest
// after setting up the fetch request, this is done by:


fetchResults = [managedObjectContext executeFetchRequest: fetchRequest error: &fetchError];

[self setAge: [fetchResults objectAtIndex:0]]; // contains the right 'Age' instance.

[self addObserver: [self Age] forKeyPath:@"yearofbirth" options: NSKeyValueObservingOptionNew context:nil];
}


Although it works, I still wonder whether it's necessary to go through the trouble of fetching the 'Age' object myself. Anyway, the 'myAge' defined above is not available again after program restart.

I hope someone knows a better/simpler solution?


Best regards,

Arthur C.

_________________________________________________________________
MSN Search, for accurate results! http://search.msn.nl

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSTabView and edit fields
  • Next by Date: Re: NSImage or CIImage? Resolution problem
  • Previous by thread: System Services: is there an alternative?
  • Next by thread: how to programatically access standard IB inspectors from within a custom palette?
  • Index(es):
    • Date
    • Thread