grrr... NSString stringWithFormat: vs. SEL typecasting
grrr... NSString stringWithFormat: vs. SEL typecasting
- Subject: grrr... NSString stringWithFormat: vs. SEL typecasting
- From: Bob Savage <email@hidden>
- Date: Sun, 27 May 2001 00:57:01 -0700
I'm having a problem. If I call my code with:
[model sortReportsBy:@"compareByPerspectiveName:"];
it works fine, but if I call it with:
[model sortReportsBy: [NSString stringWithFormat:
@"compareBy%@:",[selectedColumn identifier]] ];
(where [selectedColumn identifier] is returning @"PerspectiveName"), it does
not work. Does assembling the string with a format make it somehow
ineligible for SEL typecasting?
[@"compareByPerspectiveName:" isEqualToString:[NSString stringWithFormat:
@"compareBy%@:",[selectedColumn identifier]];
returns TRUE!
In case you think I am screwing up further down the line (I don't think so):
// in SWClientModel
// sortReportsBy:
- (void)sortReportsBy:(NSString *)sortCategory {
NSArray *sortedArray;
//sortedArrayUsingSelector:
sortedArray = [availableReports
sortedArrayUsingSelector: (SEL)[sortCategory cString]];
[availableReports release];
availableReports = [[NSMutableArray
arrayWithArray:sortedArray]retain];
}
// in SWReport
// compareByPerspectiveName:
-(NSComparisonResult)compareByPerspectiveName:(SWReport *)otherReport {
return [[self getPerspectiveName]
caseInsensitiveCompare:[otherReport getPerspectiveName]];
}