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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to