Skip to content

Instantly share code, notes, and snippets.

@ssebi
Last active August 6, 2019 14:00
Show Gist options
  • Save ssebi/6d98e98d37a073e464036a42fd3f52e9 to your computer and use it in GitHub Desktop.
Save ssebi/6d98e98d37a073e464036a42fd3f52e9 to your computer and use it in GitHub Desktop.
Diagnose RxSwift
/*
* In order to diagnose Rx and see the number of resources your project uses there are a couple
* of steps you need to take
*
* 1)
* Add this line of code somewhere in your project, for example in AppDelegate
*
*/
_ = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
.subscribe(onNext: { _ in
print("Resource count \(RxSwift.Resources.total)")
})
/*
* 2)
* This goes into the Podfile so it can download additional things needed
*
*/
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'RxSwift'
target.build_configurations.each do |config|
if config.name == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['-D', 'TRACE_RESOURCES']
end
end
end
end
end
/*
* 3)
* Lastly, go to your Xcode proj -> Build Settings -> Other Swift Flags and add the following line
*
*/
-D TRACE_RESOURCES
/*
* All set, now run your app and you should begin to see someting like this in your console
*
*/
Resource count 2910
Resource count 2910
Resource count 2910
Resource count 2910
Resource count 2910
Resource count 2910
/*
* Use your app and if you notice the number continuously increases,
* congratulations it means that you leaked memory :)
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment