[iOS] @property

MyProperty.h

#import 

@interface MyProperty : NSObject {
	int x;
	NSString *name;
}
@property int x;
@property (retain) NSString *name;

@end

MyProperty.m

#import "MyProperty.h"

@implementation MyProperty

@synthesize x;
@synthesize name;

@end

usage


#import 
#import "MyProperty.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    MyProperty *myppt = [[MyProperty alloc] init];
	NSLog(@"x is %d, name is %@", myppt.x, myppt.name);
	
	myppt.x = 19;
	myppt.name = @"bar";
	
	NSLog(@"x is %d, name is %@", myppt.x, myppt.name);
    
	[myppt release];
    [pool drain];
    return 0;
}

Comments are closed.