Created
October 12, 2018 11:26
-
-
Save nanoxd/138d3b579ae87af1c03184debb062561 to your computer and use it in GitHub Desktop.
[DispatchQueue+isMain] Determine if the current GCD Queue is the main queue #swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension DispatchQueue { | |
fileprivate static let mainQueueKey = DispatchSpecificKey<()>() | |
static func configureMainQueue() { | |
main.setSpecific(key: mainQueueKey, value: ()) | |
} | |
} | |
public extension DispatchQueue { | |
/// Easy and safe way of checking if the current queue is the main queue | |
static var isMain: Bool { | |
return getSpecific(key: mainQueueKey) != nil | |
} | |
/// Easy and safe way of checking if the current queue is the main queue | |
var isMain: Bool { | |
return getSpecific(key: DispatchQueue.mainQueueKey) != nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment