• 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
Re: How to make KVO setup persistent?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make KVO setup persistent?


  • Subject: Re: How to make KVO setup persistent?
  • From: "Arthur C." <email@hidden>
  • Date: Sat, 29 Jul 2006 15:28:59 +0200

It's not clear exactly what you're trying to achieve, but the following is certainly not a correct solution for anything.

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:


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

[self addObserver:myAge forKeyPath:@"yearofbirth"
options:NSKeyValueObservingOptionNew context:nil]; // context set to nil works indeed.
}


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.

You've now leaked an instance of Age (you lost the reference to the one you alloced in the first line).

Point taken. But that can be fixed.

It's not clear where fetchResults comes from.

I create an NSFetchRequest after which the results are obtained using:

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

[myAge index]; // to get rid of the 'fault' state (!)
It's not clear why you need to "get rid of the fault state" -- fault handling should typically be transparent.

Line removed, it's not necessary indeed.

[myAgeArray addObject: myAge];

What is myAgeArray? Is it a persistent property? You're modifying it in a non-KVO-compliant way.

This is an attempt to retain the objects fetched using the fetchRequest. But probably not a very good one - I need to work out the memory management issues first.


[self addObserver: [myAgeArray lastObject] forKeyPath:@"yearofbirth" options: NSKeyValueObservingOptionNew context:managedObjectContext];

The context here should almost certainly not be the managed object context.

Setting it to 'nil' works as well, as I don't use it in the observeValueForKeyPath method.



Thanks so far,

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


References: 
 >Re: How to make KVO setup persistent? (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: Sorting NSTableView
  • Next by Date: Re: Re: Sorting NSTableView
  • Previous by thread: Re: How to make KVO setup persistent?
  • Next by thread: Re: How to make KVO setup persistent?
  • Index(es):
    • Date
    • Thread