Created
November 7, 2010 05:38
-
-
Save honjo2/665975 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 "Simple.h" | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
Simple * simple = [[Simple alloc] init]; | |
[simple add:5]; | |
[simple add:5 second:5]; | |
int result = [simple get]; | |
NSLog(@"%d", result); // 20 | |
[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 Simple : NSObject { | |
int offset; | |
} | |
-(id)init; | |
-(void)add:(int)plus; | |
-(void)add:(int)plus second:(int)_second; | |
-(int)get; | |
@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 "Simple.h" | |
@implementation Simple | |
-(id)init { | |
self = [super init]; | |
if (self != nil) { | |
offset = 5; | |
} | |
return self; | |
} | |
-(void)add:(int)plus { | |
offset += plus; | |
} | |
-(void)add:(int)plus second:(int)_second { | |
offset += plus; | |
offset += _second; | |
} | |
-(int)get { | |
return offset; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment