user1361529
user1361529

Reputation: 2697

How _exactly_ does one integrate DTFoundation into another iOS project?

I am trying to debug a project where I suspect UI operations are being called in background threads. This link: UIViewController animations stop working describes how to use a DTFoundation code to detect if UI operations are called in background threads but I can't figure out how to integrate. I don't use Pods - its an XCode project for another app. I tried dragging DTFoundation.xcodeproj, adding it to target but I just can't get it to work. The app builds but the library does not. Any sage advice?

Upvotes: 0

Views: 369

Answers (1)

user1361529
user1361529

Reputation: 2697

Okay, for anyone looking to use DTFoundation to trap UIKit calls outside of the main thread, here is how (NOTE: This is ONLY for trapping UIKit calls - not to avail of all the other DTFoundation utilities).

1) Download DTFoundation code from here https://github.com/Cocoanetics/DTFoundation and unzip it somewhere

2) In XCode, open up your existing project you want to debug, and just copy the following .h and .m files to your project from the unzipped DTFoundation code: UIView+DTDebug, DTLog, DTObjectBlockExecutor, NSObject+DTRunTime (That's 8 files - each name above has a corresponding .h and .m)

3) Now go to your AppDelegate.mm file in your project and in the didFinishLaunchingWithOptions function add

  [UIView toggleViewMainThreadChecking];

4) Next up, set a breakpoint inside UIView+DTDebug.m at at -

(void)methodCalledNotFromMainThread:(NSString *)methodName

You will now be all set to run your master code and any time a UI operation is called outside the main thread, your code will break at this point. Now all you need to do is look at the stack trace - the first function inside your own project code (typically several lines into the trace) is the offending code. Wrap it inside

 dispatch_async(dispatch_get_main_queue(), ^{ <Offending UI code goes here> }); 

or any other way appropriate

Enjoy! This framework save many hours of flubbing around

Upvotes: 3

Related Questions