Understanding property/synthesize
Understanding property/synthesize
- Subject: Understanding property/synthesize
- From: Stefan Nobis <email@hidden>
- Date: Sat, 07 Aug 2010 17:52:28 +0200
- Mail-followup-to: email@hidden
Hi.
I'm a bit curious about the Objective-C 2.0 property/synthesize
mechanism. In all examples I've seen, an instance variable is declared
for each property. But if I leave out the instance variable like in
the following example, everything works fine, too.
----------------------------------------------------------------------
#import <Foundation/Foundation.h>
#import <stdio.h>
@interface MyClass : NSObject
@property NSInteger number;
@end
@implementation MyClass : NSObject
@synthesize number;
@end
int main() {
MyClass *obj = [[MyClass alloc] init];
[obj setNumber: 77];
printf("%d\n", (int)[obj number]);
[obj release];
return 0;
}
----------------------------------------------------------------------
So my question: What are the (possible) problems/implications if I
leave out the declarations of instance variable of properties? What
are the recommendations? More specific: Does the above also work/run
on iOS?
--
Until the next mail...,
Stefan.
_______________________________________________
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