Swift中的TimeInterval

时间:2016-06-28 13:11:39

标签: objective-c xcode swift swift3 xcode8

您好我需要将Objective-c中的这段代码转换为Swift Objective-C code 但是我遇到了Date和TimeInterval对象的问题。 Swift code Swift版本:3 Xcode版本:8.0 beta

修改 这可能是一个解决方案吗? Possible solution

编辑2: enter image description here

2 个答案:

答案 0 :(得分:1)

根据我的评论,您的代码必须是:

private func updateTimer() {
    let currentDate = NSDate()
    let timeInterval = currentDate.timeIntervalSince(self.startDate)
    let timerDate = NSDate(timerIntervalSince1970: timeInterval)
}

private func updateTimer() {
    //we don't have to create the variable "currentDate".
    let timeInterval = NSDate().timeIntervalSince(self.startDate)
    let timerDate = NSDate(timerIntervalSince1970: timeInterval)
}

答案 1 :(得分:1)

对于Swift 3,请使用日期:

@ThriftHandler("/api")
public class TGreetingServiceHandler implements TGreetingService.Iface {

    @Override
    public String greet(TName name) throws TException {
        // your logic
    }
}