• 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: @property question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @property question


  • Subject: Re: @property question
  • From: Roland King <email@hidden>
  • Date: Wed, 14 May 2008 08:41:49 +0800

Can someone expand on this a little more please and fill in some blanks about why the first version isn't KVO compliant and what it is about the second one which makes KVO work? That second piece of code

   [ [ self mutableArrayValueForKey:@"fieldArray" ] addObjectInFoo ];

is not perhaps the first thing which would spring to mind when writing new code.

Quincey Morris wrote:


On May 12, 2008, at 15:19, Craig Hopson wrote:

I think I've been the victim of some side effect that I cannot track down. With no other changes, I tried again with each style,
[ self.fieldArray addObject:inFoo ];
[ fieldArray addObject:inFoo ];
replacing all occurrences for each test, and both work - what I would have expected.


Incidentally, neither version is KVO-compliant. If you happen to have something (e.g. a NSArrayController) bound to the array property, to show Foos in the user interface, the effect of addObject (and therefore addFoo) will be to leave what's displayed out of date. This could possibly lead to unpredictable behavior or a crash.

The KVO-compliant way to add something to an array property would be something like this:

- (void)addFoo:( Bar* )inFoo
{
    [ [self mutableArrayValueForKey:@"fieldArray"] addObject:inFoo ];
}

P.S. I just noticed that the inFoo looks like it needs to be a Foo*, not a Bar*. I assume this was just a typo when you stripped down your example for posting?
_______________________________________________


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


_______________________________________________

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: @property question
      • From: Chris Hanson <email@hidden>
    • Re: @property question
      • From: "Kyle Sluder" <email@hidden>
References: 
 >@property question (From: Craig Hopson <email@hidden>)
 >Re: @property question (From: mmalc crawford <email@hidden>)
 >Re: @property question (From: Craig Hopson <email@hidden>)
 >Re: @property question (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: How to deal with property and Undo?
  • Next by Date: Re: Anybody using Pantomime or mail-core framework?
  • Previous by thread: Re: @property question
  • Next by thread: Re: @property question
  • Index(es):
    • Date
    • Thread