iOS - 在测试设备时未调用类别方法

时间:2012-05-15 19:37:59

标签: ios nsdate categories

我有这个类别:

@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];  

它在模拟器上工作正常,但在设备上甚至没有调用类别方法,任何想法?

1 个答案:

答案 0 :(得分:0)

如果在调试器中添加符号断点,它是否会得到解决?如果是这样,执行是否会停止?

您是否将此代码编译为静态.a库? GCC链接器需要使用-all_load标志来确保拾取静态库中的类别。