• 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: Triggering a Method when a Core Data Property is Altered.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Triggering a Method when a Core Data Property is Altered.


  • Subject: Re: Triggering a Method when a Core Data Property is Altered.
  • From: Volker in Lists <email@hidden>
  • Date: Wed, 7 Oct 2009 17:38:57 +0200

hi,

which Kyle told you has nothing in common with a managedobject nor was it clear how that code was used.

You have to call addObserver on the managed object and add the object that has to observe as observer. It really depends on your setup where to add what best. There exist a couple of possibilities.

If that is not clear, reread KVO documentations over again. Look at examples and start with something simple like observing the selection in your tree controller (if it is still the same application).

Volker

Am 07.10.2009 um 17:31 schrieb Joshua Garnham:

Hi,

So should I add the Observer in an NSManagedObject sub-class and call self?
Also in the email before last I sent the code that I had tried.


Cheers,
Josh.
From: Volker in Lists <email@hidden>
To: Joshua Garnham <email@hidden>
Cc: email@hidden
Sent: Wednesday, 7 October, 2009 16:09:55
Subject: Re: Triggering a Method when a Core Data Property is Altered.

Hi,

you call addObserver on that CoreData object - which is a regular NSObject descendant anyway. So just as for every other NSObject you want to observe a property of. In case of CoreData objects you have to deal with it differently than with objects you create your self in your code 8and dispose again, since unregistering as observer is necessary as well). In Core Data objects awakeFromFetch, - Insert, ... etc. They can be undoed, faulted, ... and all that you have to take into consideration when observing NSManagedObjects. which is not trivial at all in some situations, see the Mailinglist archive for that topic, it was covered just weeks ago in length.

As usual -> code makes helping easier. I am still not sure what you have tried and how. No one else on the list will no neither.


Cheers, Volker

Am 07.10.2009 um 17:05 schrieb Joshua Garnham:

Hi,

I see, how do you observe a CoreData Property?

From: Volker in Lists <email@hidden>
To: Joshua Garnham <email@hidden>
Sent: Wednesday, 7 October, 2009 8:11:48
Subject: Re: Triggering a Method when a Core Data Property is Altered.


Hi,

you have to add an observer to the CoreData entity - which is probably what you haven't done there. Also, you have to observe a property, that is observable - otherwise nothing is triggered.

Volker

Am 07.10.2009 um 07:40 schrieb Joshua Garnham:

Volker,

I have tried using the below code to add my self as an observer then trigger an action but it doesn't work.

- awakeFromNib {
[self
 addObserver: self
            forKeyPath: @"name"
               options: NSKeyValueObservingOptionNew
               context: NULL];
}
-(id)init {
        dispatch

= [[NSDictionary dictionaryWithObjectsAndKeys:@selector (doSomething:),@"name", nil] retain];
}
...
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
[self performSelector:msg withObject:object withObject:keyPath];
}


Is there something wrong that is blatantly obvious?

Cheers,
Josh.

From: Volker in Lists <email@hidden>
To: Joshua Garnham <email@hidden>
Cc: email@hidden
Sent: Tuesday, 6 October, 2009 18:57:59
Subject: Re: Triggering a Method when a Core Data Property is Altered.


Josh,

depending on where you need to get a notification:

a) within the same NSManagedObject or a relationship:http:// developer.apple.com/mac/library/documentation/Cocoa/Reference/ Foundation/Protocols/NSKeyValueObserving_Protocol/Reference/ Reference.html#//apple_ref/occ/clm/NSObject/ keyPathsForValuesAffectingValueForKey:

b) in any other object: just register as observer as described in KVO basics:http://developer.apple.com/mac/library/documentation/ Cocoa/Conceptual/KeyValueObserving/Concepts/KVOBasics.html

Take note: The triggering happens not on the change of the TextFieldCell in a table, but due to a property changing.

When you have looked into KVO - what have you tried already?


Cheers, Volker

Am 06.10.2009 um 18:45 schrieb Joshua Garnham:

> Hi.
>
> I am trying to trigger a method when A Core Data property is changed, e.g A Text Fields Text in a Table (connected to Core Data) is changed. I have looked into Key Value Observing but haven't had much luck.
>
> Cheers.
>
>
>
>
> _______________________________________________
>
> 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






Send instant messages to your online friends http://uk.messenger.yahoo.com


Send instant messages to your online friends http://uk.messenger.yahoo.com

_______________________________________________

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: 
 >Triggering a Method when a Core Data Property is Altered. (From: Joshua Garnham <email@hidden>)
 >Re: Triggering a Method when a Core Data Property is Altered. (From: Volker in Lists <email@hidden>)
 >Re: Triggering a Method when a Core Data Property is Altered. (From: Volker in Lists <email@hidden>)

  • Prev by Date: Memory corruption when moving from 10.5 to 10.6
  • Next by Date: Re: NSAttributedString always returns NO for -isEqualToAttributedString with attachments present?
  • Previous by thread: Re: Triggering a Method when a Core Data Property is Altered.
  • Next by thread: Re: Triggering a Method when a Core Data Property is Altered.
  • Index(es):
    • Date
    • Thread