我正在尝试将NSDate子类化以添加毫秒功能,它看起来像这样:
部首:
#import <Foundation/Foundation.h>
@interface DTDate : NSDate
- (id)initWithJavaMillis:(NSInteger)val;
- (NSInteger)getJavaMillis;
@end
实现:
#import "DTDate.h"
@implementation DTDate
{
NSInteger milliseconds;
}
- (id)initWithJavaMillis:(NSInteger)val
{
// Main time initialized with whole seconds
self = [super initWithTimeIntervalSince1970:(NSTimeInterval)(val / 1000)];
// Also hold on to millis part
if (self)
{
milliseconds = val % 1000;
}
return self;
}
- (NSInteger)getJavaMillis
{
return [super timeIntervalSince1970] * 1000 + milliseconds;
}
@end
现在我正试图像这样使用它:
return [DTDate initWithJavaMillis:retVal];
No known class method for selector 'initWithJavaMillis:'
但它不起作用。我之前从未使用过自定义初始化程序,因此它应该是简单的。有什么指针吗?
答案 0 :(得分:1)