Created
April 19, 2013 09:55
-
-
Save komamitsu/5419340 to your computer and use it in GitHub Desktop.
Objective-C small sample codes
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 "User.h" | |
| int main(void) { | |
| User *foo = [[User alloc] init]; | |
| foo.name = @"Komamitsu"; | |
| foo.age = 123; | |
| NSLog(@"%@", [foo hello:@"Bye"]); | |
| 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 User : NSObject | |
| - (NSString*)hello:(NSString*)msg; | |
| @property(copy) NSString *name; | |
| @property int age; | |
| @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 "User.h" | |
| @implementation User | |
| @synthesize age; | |
| @synthesize name; | |
| - (NSString*)hello:(NSString*)msg { | |
| return [NSString stringWithFormat: @"Hello, my name is %@. %@\n", self.name, msg]; | |
| } | |
| @end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ clang -Wall -lobjc -framework Foundation -fobjc-gc-only main.m User.m