• 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: Detecting Managed Object Property Change From Undo Redo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting Managed Object Property Change From Undo Redo


  • Subject: Re: Detecting Managed Object Property Change From Undo Redo
  • From: Kyle Sluder <email@hidden>
  • Date: Mon, 26 Jan 2015 00:03:30 -0600

On Sun, Jan 25, 2015, at 05:16 PM, Jerry Krinock wrote:
• Amount of code required is the same or less
> • Ability to coalesce and filter notifications per object or name
> • When an observer is being torn down you can remove all observers with
> one line of code,
>      [NSNotificationCenter removeObserver:self].

This is a dangerous API. If your superclass has registered for any
observations, you will unregister before your superclass hears about it.

> With KVO, if I recall correctly, you need to remember and remove each
> observance, arghhhh.

You can use the magic of C's sizeof keyword to avoid repeating yourself
for each observed keypath:

static void *observationContext = &observationContext;
static NSString *observedKeypaths[] = {@"prop1", @"prop2"};

- (void)startObservingModelObject:(MyModelObject *)obj
{
  for (int i = 0; i < sizeof(observedKeypaths) /
  sizeof(*observedKeypaths); i++)
    [obj addObserver:self forKeyPath:observedKeypaths[i] options:0
    context:observationContext];
}

- (void)stopObservingModelObject:(MyModelObject *)obj
{
  for (int i = 0; i < sizeof(observedKeypaths) /
  sizeof(*observedKeypaths); i++)
    [obj removeObserver:self forKeyPath:observedKeypaths[i]
    context:observationContext];
}

--Kyle Sluder

_______________________________________________

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: Detecting Managed Object Property Change From Undo Redo
      • From: Jerry Krinock <email@hidden>
References: 
 >Detecting Managed Object Property Change From Undo Redo (From: Richard Charles <email@hidden>)
 >Re: Detecting Managed Object Property Change From Undo Redo (From: Mike Abdullah <email@hidden>)
 >Re: Detecting Managed Object Property Change From Undo Redo (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Any way to force a window under the menu bar?
  • Next by Date: Re: Detecting Managed Object Property Change From Undo Redo
  • Previous by thread: Re: Detecting Managed Object Property Change From Undo Redo
  • Next by thread: Re: Detecting Managed Object Property Change From Undo Redo
  • Index(es):
    • Date
    • Thread