Skip to content

Instantly share code, notes, and snippets.

@honjo2
Created November 7, 2010 05:38
Show Gist options
  • Save honjo2/665975 to your computer and use it in GitHub Desktop.
Save honjo2/665975 to your computer and use it in GitHub Desktop.
[Objective-C] シンプルなクラス
#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;
}
#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
#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