私はこのカテゴリを持っています:
@interface NSDate (PrettyDate)
- (NSString *)prettyDate;
@end
#import "NSDate+PrettyDate.h"
@implementation NSDate (PrettyDate)
- (NSString *)prettyDate
{
NSString *prettyTimestamp = nil;
float delta = [self timeIntervalSinceNow] * -1;
if (delta < 60) {
prettyTimestamp = @"Just now";
} else if (delta < 120) {
prettyTimestamp = @"One minute ago";
} else if (delta < 3600) {
prettyTimestamp = [NSString stringWithFormat:@"%d minutes ago", (int) floor(delta/60.0) ];
} else if (delta < 7200) {
prettyTimestamp = @"One hour ago";
} else if (delta < 86400) {
prettyTimestamp = [NSString stringWithFormat:@"%d hours ago", (int) floor(delta/3600.0) ];
} else if (delta < ( 86400 * 2 ) ) {
prettyTimestamp = @"One day ago";
} else if (delta < ( 86400 * 7 ) ) {
prettyTimestamp = [NSString stringWithFormat:@"%d days ago", (int) floor(delta/86400.0) ];
} else {
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
prettyTimestamp = [NSString stringWithFormat:@"On %@", [formatter stringFromDate:self]];
}
return prettyTimestamp;
}
@end
そして、私はそれを次のように呼んでいます:
NSDateFormatter *currentFormat = [[NSDateFormatter alloc] init];
currentFormat.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *date = [currentFormat dateFromString:dateString];
cell.detailTextLabel.text = [date prettyDate];
シミュレーターでは問題なく動作しますが、デバイスではカテゴリ メソッドが呼び出されません。何かアイデアはありますか?