• 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: KVO autonotifying complaining about custom setter return value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO autonotifying complaining about custom setter return value


  • Subject: Re: KVO autonotifying complaining about custom setter return value
  • From: "Jim Turner" <email@hidden>
  • Date: Wed, 5 Mar 2008 17:10:46 -0600

On Wed, Mar 5, 2008 at 4:14 PM, mmalc crawford <email@hidden> wrote:
>
>  On Mar 5, 2008, at 1:40 PM, Adam P Jenkins wrote:
>
>  > If you define a @property in the interface, then in the
>  > implementation you either need use @synthesize to have the compiler
>  > automatically generate a getter and setter, or use @dynamic to
>  > inform the compiler that you will provide the appropriately named
>  > getter and setter methods.
>  >
>  There is no *need* to specify @dynamic.  In fact, doing so will
>  conceal a bug (at least until runtime...) if you don't intend to
>  create the appropriate methods at runtime (as do, for example, managed
>  objects) but forget to provide an implementation.  If you don't
>  specify @dynamic, then the compiler will warn you if you don't supply
>  appropriate methods at compile time.
>
>
>  > If you need to define the accessors yourself because the auto-
>  > generated ones don't do what you want, then use @dynamic instead
>  > like this:
>  > @implementation Person
>  > @dynamic firstName;
>  >
>  > - (NSString*)firstName { ... }
>  > - (void)setFirstName:(NSString *)newName { ... }
>  > @end
>
>  It's perfectly reasonable also to do either:
>
>
>  @implementation Person
>
>
>  - (NSString*)firstName { ... }
>  - (void)setFirstName:(NSString *)newName { ... }
>  @end
>
>
>  or, for example:
>
>
>  @implementation Person
>  @synthesize firstName;
>
>
>  - (void)setFirstName:(NSString *)newName { ... }
>  @end
>
>
>  In the latter case, the compiler will just synthesise -firstName.
>
>
>  One further issue for the sake of raising it:
>
> > @property (setter=mySetMethod:,getter=myMethod) id valueTest;
>  >
>
>  Note that this implies that the accessor methods are atomic.  It's
>  comparatively rare (unless you're using GC) that Cocoa developers
>  implement atomic accessor methods, so you'd typically specify:
>
>  @property (nonatomic, setter=mySetMethod:,getter=myMethod) id valueTest;
>
>
>  mmalc
>

Ok first, mmalc, thank you for taking the time to point out exactly
what I needed to see to understand where I was going wrong.  My
problem stemmed from the misguided idea that properties were required
for KVC/KVO.  Chris' comment about "using non-default names" makes
much more sense now.

Second, for my situation, I ended up with an interface that looks like this:

@property (getter=getValueForBindings, setter=setValueForBindings:,
assign, nonatomic) id value;

And an implementation:

-(void) setValueForBindings:(id)_value
{
	[self willChangeValueForKey:@"value"];
	{
		 BOOL didSetOK = [self setStringValue:(NSString *)_value];
               // Do something with didSetOK
	}
	[self didChangeValueForKey:@"value"];
}

-(id) getValueForBindings
{
	return( value );
}

Then binding my interface to the key 'valueForBindings'.  Not the
prettiest, but it's required for my situation.

Thanks again to everyone for all the help.

--
Jim
http://nukethemfromorbit.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

  • Follow-Ups:
    • Re: KVO autonotifying complaining about custom setter return value
      • From: Chris Suter <email@hidden>
References: 
 >KVO autonotifying complaining about custom setter return value (From: "Jim Turner" <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: "Kyle Sluder" <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: Chris Suter <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: "Jim Turner" <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: mmalc crawford <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: "Jim Turner" <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: Adam P Jenkins <email@hidden>)
 >Re: KVO autonotifying complaining about custom setter return value (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: KVO autonotifying complaining about custom setter return value
  • Next by Date: large documents with doc based app
  • Previous by thread: Re: KVO autonotifying complaining about custom setter return value
  • Next by thread: Re: KVO autonotifying complaining about custom setter return value
  • Index(es):
    • Date
    • Thread