如何将此 NSTimeInterval 行从 Swift 转换为 Objective-C
How to convert this NSTimeInterval line from Swift to Objective-C
如何将其转换为 Objective-C?
let date = NSDate(timeIntervalSinceReferenceDate: interval)
我试过这个:
NSDate *date = [NSDate timeIntervalSinceReferenceDate: (interval)];
当然会产生错误。
告诉我:选择器 timeIntervalSinceReferenceDate:
没有已知的 class 方法
这里还有一些上下文:
NSTimeInterval interval = [[NSDate alloc]init].timeIntervalSinceReferenceDate + [NSDate weekInSeconds].doubleValue;
NSDate *date = [NSDate timeIntervalSinceReferenceDate: (interval)];
return [self isSameWeekAsDate:(date)];
timeIntervalSinceReferenceDate:
不是在 NSDate
class 上实现的方法。当从 Objective-C 桥接到 Swift 时,Swift 会使用初始化器进行一些重命名。
为了用参考日期初始化 Objective-C 中的 NSDate
对象,您必须调用 class 方法 dateWith...
或实例方法 initWith...
:
NSDate * const date = [NSDate dateWithTimeIntervalSinceReferenceDate: timeInterval];
或...
NSDate * const date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: timeInterval];
我在此处添加了 const
以使其与 Swift 代码与 let
声明更匹配。
如何将其转换为 Objective-C?
let date = NSDate(timeIntervalSinceReferenceDate: interval)
我试过这个:
NSDate *date = [NSDate timeIntervalSinceReferenceDate: (interval)];
当然会产生错误。
告诉我:选择器 timeIntervalSinceReferenceDate:
没有已知的 class 方法这里还有一些上下文:
NSTimeInterval interval = [[NSDate alloc]init].timeIntervalSinceReferenceDate + [NSDate weekInSeconds].doubleValue;
NSDate *date = [NSDate timeIntervalSinceReferenceDate: (interval)];
return [self isSameWeekAsDate:(date)];
timeIntervalSinceReferenceDate:
不是在 NSDate
class 上实现的方法。当从 Objective-C 桥接到 Swift 时,Swift 会使用初始化器进行一些重命名。
为了用参考日期初始化 Objective-C 中的 NSDate
对象,您必须调用 class 方法 dateWith...
或实例方法 initWith...
:
NSDate * const date = [NSDate dateWithTimeIntervalSinceReferenceDate: timeInterval];
或...
NSDate * const date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: timeInterval];
我在此处添加了 const
以使其与 Swift 代码与 let
声明更匹配。