• 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: mmalc crawford <email@hidden>
  • Date: Wed, 5 Mar 2008 14:14:07 -0800


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

_______________________________________________

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: "Jim Turner" <email@hidden>
    • Re: KVO autonotifying complaining about custom setter return value
      • From: Bill Garrison <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>)

  • Prev by Date: Re: NSPreferencePane with my own private framework?
  • Next by Date: Re: Best way to hook up Font Panel to floater (that isn't first responder)?
  • 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