Swift 3 has DispatchWorkItem
:
let task = DispatchWorkItem { print("do something") }
// execute task in 2 seconds
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2, execute: task)
// optional: cancel task
task.cancel()
More Related Contents:
- What is the purpose of willSet and didSet in Swift?
- How to convert a date string with optional fractional seconds using Codable in Swift?
- Swift double to string
- Attach parameter to button.addTarget action in Swift
- The use of Swift 3 @objc inference in Swift 4 mode is deprecated?
- How do I get the count of a Swift enum?
- Xcode 8 Beta 3 Use Legacy Swift issue
- Difference between == and ===
- What is the in-practice difference between generic and protocol-typed function parameters?
- Input from the keyboard in command line application
- Shuffle array swift 3
- When should I access properties with self in swift?
- Call a method from a String in Swift
- Express for loops in swift with dynamic range
- Iterate through files in a folder and its subfolders using Swift’s FileManager
- How change background color if using NavigationView in SwiftUI?
- What does the dollar sign do in Swift / SwiftUI?
- Convert Float to Int in Swift
- Filter non-digits from string
- How to remove the left and right Padding of a List in SwiftUI?
- How do I encode enum using NSCoder in swift?
- How do I see which version of Swift I’m using?
- try, try! & try? what’s the difference, and when to use each?
- Swift 4 Decodable – Dictionary with enum as key
- Get Description of Emoji Character
- iOS11 swift silent push (background fetch, didReceiveRemoteNotification) is not working anymore
- Convert Firebase Firestore Timestamp to Date (Swift)?
- SwiftUI 2: the way to open view in new window
- Reasons to include function in protocol definition vs. only defining it in the extension?
- Programmatically Screenshot | Swift 3, macOS