Objective C 代码片段(类别)

时间:2023-03-09 17:06:31
Objective C 代码片段(类别)
 @interface NSString (reverse)

 -(NSString *) reverseString;

 @end
 @implementation NSString (reverse)

 -(NSString *) reverseString {
int length = [self length];
NSMutableString *reversedString; reversedString = [[NSMutableString alloc] initWithCapacity: length]; while(length > ) {
[reversedString appendString:[NSString stringWithFormat:@"%C", [self characterAtIndex:--length]]];
}
return [reversedString autorelease];
}
@end