Created
December 3, 2017 12:59
-
-
Save software-mariodiana/bbe3117827aee322f72c8ae4c80e33e8 to your computer and use it in GitHub Desktop.
Ensure UIView bounds method is called from main thread.
This file contains 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
- (CGRect)bounds | |
{ | |
// The architecture of the framework is such that bounds is sometimes accessed from a | |
// non-main thread. iOS 11 complains about this sort of thing. | |
__block CGRect theBounds = CGRectNull; | |
if ([NSThread isMainThread]) | |
{ | |
// Trying to grab the main thread if you're on the main thread causes deadlock. | |
theBounds = [super bounds]; | |
} | |
else | |
{ | |
// Submits a block object for execution on a dispatch queue and waits until that block completes. | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
theBounds = [super bounds]; | |
}); | |
} | |
return theBounds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment