fastred / DeallocationChecker

Catch leaking view controllers without opening Instruments.
http://holko.pl/2017/06/26/checking-uiviewcontroller-deallocation/
MIT License
798 stars 29 forks source link

Doesn't work when imported in an Objective-c project? #4

Closed sarperdag closed 7 years ago

sarperdag commented 7 years ago

Trying to use this in an objC project, but it never fires an error even if I'm 100% sure the VC is not being deallocated...

fastred commented 7 years ago

Can you try putting a breakpoint on the line with assertion to see if it's executed?

sarperdag commented 7 years ago

Tried that but the breakpoint gets hit at the end of the function. Can't even debug it line by line and see what's going on... Don't have much experience with using Swift code in objective-c projects, maybe Xcode is showing smt non-sense?

fastred commented 7 years ago

I think this is caused by #if DEBUG being false and skipping the whole implementation. Can you see if adding this in your Podfile helps?

# Enable DEBUG flag in Swift for DeallocationChecker
post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'DeallocationChecker'
            target.build_configurations.each do |config|
                if config.name == 'Debug'
                    config.build_settings['OTHER_SWIFT_FLAGS'] = '-DDEBUG'
                end
            end
        end
    end
end
sarperdag commented 7 years ago

Still not working. This time it's another error:

Pods/DeallocationChecker/Sources/DeallocationChecker.swift:45:17: Method 'objc_dch_checkDeallocation(delay:)' with Objective-C selector 'dch_checkDeallocationAfterDelay:' conflicts with method 'dch_checkDeallocation(afterDelay:)' with the same Objective-C selector

fastred commented 7 years ago

@sarperdag Thanks for reporting!

I just pushed DeallocationChecker 2.0.1 which should fix this issue. No need for that post_install phase I mentioned before too.

sarperdag commented 7 years ago

OK updated to 2.0.1 but here's a new error :)

Implicit declaration of function 'dch_checkDeallocation' is invalid in C99

I'm importing the library using:

import "DeallocationChecker-Swift.h"

fastred commented 7 years ago

Can you try importing using?

@import DeallocationChecker;
sarperdag commented 7 years ago

Already tried that, not working :)

-- Sarp Erdag

On 6 Nov 2017 21:38 +0300, Arek Holko notifications@github.com, wrote:

Can you try importing using? @import DeallocationChecker; — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

fastred commented 7 years ago

I think I know what's wrong. It's a method on UIViewController, so from Objective-C you have to call it this way:

[self dch_checkDeallocation];

Full example:

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    [self dch_checkDeallocation];
}
sarperdag commented 7 years ago

yup, that's the reason. Seems to be working fine now. Thanks for the support!

fastred commented 7 years ago

Great to finally get this working under Obj-C! 😃