Last active
December 18, 2015 13:59
-
-
Save InPermutation/5794203 to your computer and use it in GitHub Desktop.
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> | |
| @implementation Person : CPObject | |
| { | |
| CPString name; | |
| } | |
| + (id)personWithName:(CPString)aName | |
| { | |
| return [[self alloc] initWithName:aName]; | |
| } | |
| - (id)initWithName:(CPString)aName | |
| { | |
| self = [super init]; | |
| name = aName; | |
| return self; | |
| } | |
| - (void)setName:(CPString)aName | |
| { | |
| name = aName; | |
| } | |
| - (CPString)name | |
| { | |
| return name; | |
| } | |
| @end | |
| // Reversing Category for CPString | |
| @implementation CPString (Reversing) | |
| - (CPString)reverse | |
| { | |
| var reversedString = "", | |
| index = [self length]; | |
| while(index--) | |
| reversedString += [self characterAtIndex:index]; | |
| return reversedString; | |
| } | |
| @end | |
| var john = [Person personWithName:"John"]; | |
| alert([john name]); | |
| [john setName:"Ralph"]; | |
| alert("John changed his name to "+[john name]+" which is "+[[john name] reverse]+" backwards."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment