You just have to add your timer to the main runloop as follow:
Swift 4.2
RunLoop.main.add(timer, forMode: .common)
Swift 3
RunLoop.main.add(alarm, forMode: .commonModes)
Swift 2.x
NSRunLoop.mainRunLoop().addTimer(alarm, forMode: NSRunLoopCommonModes)
More Related Contents:
- ViewController.Type does not have a member named
- How can I make a countdown with NSTimer?
- OSX Swift open URL in default browser
- Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- How to install Xcode Command Line Tools
- Git ignore file for Xcode projects
- Safe (bounds-checked) array lookup in Swift, through optional bindings?
- How to use/install gcc on Mac OS X 10.8 / Xcode 4.4
- Expected Declaration Error using Swift
- Change templates in Xcode
- Can I have multiple Xcode versions installed?
- Error “Thread 1: breakpoint 2.1”
- IBOutlet is nil, but it is connected in storyboard, Swift
- Swift Protocol Extensions overriding
- ‘var’ parameters are deprecated and will be removed in Swift 3
- On mac, g++ (clang) fails to search /usr/local/include and /usr/local/lib by default
- “Use of undeclared type” in Swift, even though type is internal, and exists in same module
- Creating NSData from NSString in Swift
- macOS ‘wchar.h’ File Not Found
- x86 Assembly on a Mac
- Permanently configuring LLDB (in Xcode 4.3.2) not to stop on signals
- Limiting UIDatePicker dates from a particular time. Such as Input DOB to a restricted age limit
- Xcode Beta 6.1 and Xcode 6 GM stuck indexing for weird reason
- What is Communications error: OS_xpc_error in Xcode 6?
- Xcode swift indexing forever
- Print unicode character from variable (swift)
- ‘#selector’ refers to a method that is not exposed to Objective-C
- Moving Files into a Real Folder in Xcode
- Animating a constraint in Swift
- How to check if XCode command line tools are installed?