Created
November 7, 2010 06:57
-
-
Save honjo2/665993 to your computer and use it in GitHub Desktop.
[Objective-C] プロパティ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface Property : NSObject { | |
int one; | |
int two; | |
} | |
- (id) initWithTwo:(int)_two; | |
@property int one; | |
@property(readonly) int two; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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