• 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: Question about model observers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about model observers


  • Subject: Re: Question about model observers
  • From: Eric Giguere <email@hidden>
  • Date: Tue, 11 May 2010 10:53:56 -0400

Hi Keary

Also my though, this is a job for custom accessors.

I also guess that your answer concerning the collections don't include the cases where you do it outside the model but in the controller layer. This has proven to be working in other parts of my app:
	[personsController addObserver: self
			   forKeyPath: @"arrangedObjects.count"
			   options: NSKeyValueObservingOptionNew
			   context: nil];

But that's in another situation where this time, the job really is for the controller layer to take care of it since it involves

Thank you for your answer!
Eric.

On 2010-05-11, at 10:43 AM, Keary Suska wrote:

> On May 11, 2010, at 8:10 AM, Eric Giguere wrote:
>
>> Everybody tends to point in using the KVO notifications instead of the custom accessors, even if those are generated. Ok, but I couldn't make it work. Using controllers, no problem but what if I want my parent entity to be its own observer? After all, I am talking here about a relationship where children are "owned" by its parent. The behaviour on my parent when child list is modifies shouldn't require to go out of the model and use controllers. So I tried creating an observer this way, of course, didn't work:
>>
>> [self addObserver:self forKeyPath:@"needIngredients" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];
>>
>> Up there, the needIngredients is my many relationship property.
>>
>> I Apple's documentation, I also read about setting the parent as a listener to an attribute of each child in the list! Does not make sense at all. And anyway, if the first place if you want to add / remove self as observer in each of your children, you must supply custom accessor methods to make that association don't we? That kinds of go back to square 1 and define custom accessor methods.
>>
>> So the real question here:
>> What is the "right" method to have those add / remove notification in the model? Custom accessors, KVO?
>> If KVO should be the way, then what would be the right approach using only model entities to have this working? The controller layer should never be involved in that kind of logic.
>
> Just in case it isn't clear, you can not observe changes to the contents of any collection. To use KVO effectively, you need to know why this is the case, although it is outside the scope of my current response.
>
> Now that that is out of the way, I would say that the only sensible approach (AFAIK) is to implement custom accessors.
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>

Eric Giguere
email@hidden



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: Question about model observers
      • From: Keary Suska <email@hidden>
References: 
 >Question about model observers (From: Eric Giguere <email@hidden>)
 >Re: Question about model observers (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: Question about model observers
  • Next by Date: Re: Question about model observers
  • Previous by thread: Re: Question about model observers
  • Next by thread: Re: Question about model observers
  • Index(es):
    • Date
    • Thread