iiiyu / MainThreadGuard

:guardsman: Tracking UIKit access on main thread

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MainThreadGuard

Tracking UIKit access on main thread

[![CI Status](http://img.shields.io/travis/Khoa Pham/MainThreadGuard.svg?style=flat)](https://travis-ci.org/Khoa Pham/MainThreadGuard) Version License Platform Swift

Description

This is just a Swift port of PSPDFUIKitMainThreadGuard.m using swizzling on UIView extension

Usage

  • Just import the framework

Features

  • setNeedsLayout
  • setNeedsDisplay
  • setNeedsDisplayInRect:

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"
    }
  }
}

Installation

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'

Credit

Credit goes to PSPDFUIKitMainThreadGuard.m

Author

Khoa Pham, onmyway133@gmail.com

License

MainThreadGuard is available under the MIT license. See the LICENSE file for more info.

About

:guardsman: Tracking UIKit access on main thread

License:Other


Languages

Language:Swift 79.7%Language:Ruby 20.3%