Skip to content

Instantly share code, notes, and snippets.

@honjo2
Created November 7, 2010 06:57
Show Gist options
  • Save honjo2/665993 to your computer and use it in GitHub Desktop.
Save honjo2/665993 to your computer and use it in GitHub Desktop.
[Objective-C] プロパティ
#import <Foundation/Foundation.h>
#import "Property.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Property * property = [[Property alloc] initWithTwo:10];
property.one = 5;
NSLog(@"%d", property.one); // 5
NSLog(@"%d", property.two); // 10
[pool drain];
return 0;
}
#import <Foundation/Foundation.h>
@interface Property : NSObject {
int one;
int two;
}
- (id) initWithTwo:(int)_two;
@property int one;
@property(readonly) int two;
@end
#import "Property.h"
@implementation Property
@synthesize one, two;
- (id) initWithTwo:(int)_two {
self = [super init];
if (self != nil) {
two = _two;
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment