Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created August 25, 2009 18:06
Show Gist options
  • Save kyanny/174891 to your computer and use it in GitHub Desktop.
Save kyanny/174891 to your computer and use it in GitHub Desktop.
#import <Cocoa/Cocoa.h>
@interface Split : NSObject
{
}
- (NSArray *)split:(NSString *)string;
@end
@implementation Split
- (NSArray *)split:(NSString *)string
{
NSArray *array;
array = [string componentsSeparatedByString:@","];
return array;
}
@end
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *string = @"foo,bar,baz";
NSArray *array;
id splitter;
splitter = [[Split alloc] init];
array = [splitter split:(NSString *)string];
printf("%d\n", [array count]);
NSEnumerator *enumerator;;
enumerator = [array objectEnumerator];
NSString *tmp;
while (tmp = [enumerator nextObject]) {
NSLog(tmp);
}
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment