- (NSString *)ordinalSuffixFromInt:(int)number {
NSArray *cSfx = [NSArray arrayWithObjects:@"th", @"st", @"nd", @"rd", @"th", @"th", @"th", @"th", @"th", @"th", nil];
NSString *suffix = @"th";
number = abs(number % 100);
if ((number < 10) || (number > 19)) {
suffix = [cSfx objectAtIndex:number % 10];
}
return suffix;
}
Тест:
- (void)test {
for (int day=1; day<=31; day++) {
NSLog(@"ordinal: %d%@", day, [self ordinalSuffixFromInt:day]);
}
}