CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Apr 2017 |
| SwiftSwift Version | 3.0 |
| SPMSupports SPM | ✗ |
Maintained by Khoa Pham.
Tracking UIKit access on main thread
This is just a Swift port of PSPDFUIKitMainThreadGuard.m using swizzling on UIView extension
Call Guard.setup
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// setup
Guard.setup()
return true
}Try accessing UIKit from another thread and MainThreadGuard will assert
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
let label = UILabel()
view.addSubview(label)
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
label.text = "Setting text on background thread"
}
}
}MainThreadGuard is available through CocoaPods. To install it, simply add the following line to your Podfile:
You should add this to Debug configuration only
pod "MainThreadGuard", git: 'https://github.com/onmyway133/MainThreadGuard', configurations: 'Debug'Khoa Pham, [email protected]
MainThreadGuard is available under the MIT license. See the LICENSE file for more info.