Objective C 代码片段(类别)

1 @interface NSString (reverse)
2 
3 -(NSString *) reverseString;
4 
5 @end
 1 @implementation NSString (reverse)
 2  
 3 -(NSString *) reverseString {
 4     int length = [self length];
 5     NSMutableString *reversedString;
 6     
 7     reversedString = [[NSMutableString alloc] initWithCapacity: length];
 8     
 9     while(length > 0) {
10         [reversedString appendString:[NSString stringWithFormat:@"%C", [self characterAtIndex:--length]]];
11     }
12     return [reversedString autorelease]; 
13 }    
14  @end

 

posted @ 2014-05-08 16:47  zendwang  阅读(108)  评论(0编辑  收藏  举报