A guard to help you check if you make UI changes not in main thread
Swift Ruby Objective-C
Switch branches/tags
Nothing to show
Latest commit 3da1696 Jun 6, 2017 @olddonkey olddonkey Update README.md



ODUIThreadGuard is a guard to help check if you make UI changes not in main thread.

As Xcode 9 embedded this function into Xcode, there is no reason to maintain this project in the feature, Happy Coding.

Carthage compatible CocoaPods Support Swift Version License MIT

ODUIThreadGuard is a guard to help check if you make UI changes not in main thread. Highly recommend you add this file to your project as early as possible.



  • Passive implementation
  • Throw an assertion if setNeedsDisplay, setNeedsLayout, or setNeedsDisplayInRect: is called for instantiation of any UIView
  • Get the thread stack to help you locate where you make the mistake


No matter which way you use ODUIThreadGuard, no need to import any files, it is a extension of UIView, so it will work automatically.


You can use CocoaPods to install ODUIThreadGuard by adding it to your Podfile:

platform :ios, '8.0'
pod 'ODUIThreadGuard'

Then drop ODUIThreadGuard.swift into your porject.


Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/YourLibrary.framework to an iOS project.

github "olddonkey/ODUIThreadGuard"


  1. Download and drop ODUIThreadGuard.swift in your project.
  2. Congratulations!

You can change the pre compile flag to change the setting, in default, this only runs in DEBUG mode, so won't affect users in Release.


  • iOS 8.0+
  • Swift 3

The main development of ODUIThreadGuard is based on Swift 3.


Follow and contact me through email: olddonkeyblog@gmail.com. If you find an issue, just open a ticket on it. Pull requests are warmly welcome as well.


ODUIThreadGuard is released under the MIT license. See LICENSE for details.