• 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: +keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: +keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class


  • Subject: Re: +keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class
  • From: Doug Knowles <email@hidden>
  • Date: Fri, 18 Sep 2009 10:30:14 -0400

Thanks for the help; all better now. Comments inline.

On Thu, Sep 17, 2009 at 12:42 PM, Quincey Morris <
email@hidden> wrote:

> On Sep 17, 2009, at 05:44, Doug Knowles wrote:
>
>  In a CoreData entity called "Topic", I have a to-many relationship (to
>> other
>> Topics) called "children" to implement a hierarchy. In a category on
>> Topic,
>> I have implemented a property called "orderedChildren" which returns a
>> sorted array of the children. In order to ensure that "orderedChildren" is
>> recognized as a property of the Topic entity, I have defined
>> "orderedChildren" as an optional, transient attribute of Topic of unknown
>> type (since NSArray or id isn't supported). CoreData generates a property
>> declaration for ""orderedChildren" with type UNKNOWN_TYPE, and I have
>> #defined UNKNOWN_TYPE as "id" in my precompiled header.
>>
>
> It's not at all obvious that following this strategy (creating the
> transient attribute) does you any good whatsoever. OTOH, it's not at all
> obvious that it does any harm WRT to the problem you're having.


I did this in a misguided attempt to eliminate a unimplemented method
warning, which was properly fixed by including the category's header.


>
>  What doesn't work is defining a class method
>> +keyPathsForValuesAffectingOrderedChildren,
>> which I'd like to use to cause changes in the "children" relationship to
>> trigger change notifications for "orderedChildren".
>> keyPathsForValuesAffectingOrderedChildren is never called. (Overriding
>> keyPathsForValuesAffectingValueForKey: from a category is verboten.)
>>
>
> Prima facie, the reason 'keyPathsForValuesAffectingOrderedChildren' doesn't
> get called would be that nothing is observing the property. Maybe that
> aspect deserves attention ahead of the Core Data side of it. Have you tried
> writing some debugging code that (a) installs a KVO observer on the
> "orderedChildren" property of a Topic object, and (b) changes the "children"
> property, to see whether (c) "observeValueForKeyPath:..." is invoked for key
> "orderedChildren"?
>

Sigh, And thereby hangs the problem: the observer I thought I added was
missing. Adding the observer back yields the expected results,
and keyPathsForValuesAffectingOrderedChildren is being called.


>
> Narrowing the problem definition might be the most useful thing you could
> do.
>
> Also, sorry if it's a stupid question, but you have checked the console log
> for exception messages, haven't you? It often happens, with KVO-related
> problems, that an application can appear to run *almost* correctly after an
> exception is logged and ignored.
>
>
There are no stupid questions, especially from people like yourself willing
to lend some assistance here. In this case, I have a "permanent" (if
sometimes disabled) on objc_exception_throw that I use to help make sure I
don't miss exceptions.

Many thanks again.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >+keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class (From: Doug Knowles <email@hidden>)
 >Re: +keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Populating TableView Via Button.
  • Next by Date: Re: Populating TableView Via Button.
  • Previous by thread: Re: +keyPathsForValuesAffecting<Key> not working for a category-implemented property on a CoreData class
  • Next by thread: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • Index(es):
    • Date
    • Thread