Skip to content

Instantly share code, notes, and snippets.

@InPermutation
Last active December 18, 2015 13:59
Show Gist options
  • Select an option

  • Save InPermutation/5794203 to your computer and use it in GitHub Desktop.

Select an option

Save InPermutation/5794203 to your computer and use it in GitHub Desktop.
@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