2010-05-25 51 views

回答

2

makeObjectsPerformSelector遍歷數組。如果你想使用它而不是更快的迭代方法,請這樣做:

@interface NSString (MyCategory) 
-(void) localizeToArray:(NSMutableArray *)ioArray; 
@end 

@implementation NSString (MyCategory) 
-(void) localizeToArray:(NSMutableArray *)ioArray { 
    [ioArray addObject:[[NSBundle mainBundle] localizedStringForKey:self value:self table:nil]]; 
} 
@end 

@interface NSArray (MyCategory) 
-(NSArray *) arrayWithLocalizedStrings; 
@end 

@implementation NSArray (MyCategory) 
-(NSArray *) arrayWithLocalizedStrings { 
    NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]]; 
    [self makeObjectsPerformSelector:@selector(localizeToArray:) withObject:result]; 
    return result; 
} 
@end 
+0

謝謝。正如你指出的那樣,迭代看起來更有吸引力。 – RunLoop 2010-05-25 06:01:30

相關問題