如何声明(?)NSTimer函数?

时间:2015-01-20 01:29:35

标签: ios xcode swift

我想使用以下内容:
class func sleepForTimeInterval(_ ti:NSTimeInterval)
我发现here这是一个NSTimer函数。我无法弄清楚如何以及在何处声明该功能。我想在执行另一个函数之前延迟0.1秒。

1 个答案:

答案 0 :(得分:0)

如果你想在0.1之后做一些事情,你可以试试这段代码:

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    // do something after delay
});

对于初学者来说,如果您可以查看文档,那就是最好的。以下是有关NSTimer的链接:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/index.html

我认为你不能像使用NSTimer所做的那样做。