设置计时器时.RunLoop.Modes.default中的“表达式类型不明确,没有更多上下文”

时间:2019-10-14 18:23:09

标签: swift xcode macos

这是我的Route::view('/', 'contacts.index', ['contacts' => App\Contact::all()]);

AppDelegate.swift

该行的末尾import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { let timer = Timer(fire: Date(), interval: 60, repeats: true, block: { timer in print("timer") }) RunLoop.current.add(timer, forMode: .RunLoop.Modes.default) } } (特别是RunLoop部分)显示错误:

  

表达式类型不明确,没有更多上下文。

知道我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:2)

您能尝试一下吗?

func applicationDidFinishLaunching(_ aNotification: Notification) {
    let timer = Timer(fire: Date(), interval: 60, repeats: true, block: { timer in
        print("timer")
    })

    RunLoop.current.add(timer, forMode: .default)
}