soulkito
soulkito

Reputation: 236

Is dealloc always called? Even when you swipe close an app?

I wonder if dealloc is always called when you close a ViewController in Objective-C for iOS. I've done some tests and it seems like it. Except I don't get any logs when I swipe close the application. I figured that maybe XCode doesn't log things if you fully close the app like that.

The reason I wonder this is because I'm sending analytic data when one of the ViewControllers closes and I kinda need to know if dealloc is always called or if there's any better way doing this.

Upvotes: 0

Views: 577

Answers (2)

user3168444
user3168444

Reputation: 21

If you want to get notified when app is killed via Swiping , you can use applicationWillTerminate method and in this method , you can check for current view controller in navigation stack and send analytical data for that View controller .

Upvotes: 2

Droppy
Droppy

Reputation: 9721

It's not defined when dealloc will be called for a view controller (or pretty much any class), therefore don't use it for sending analytics.

Use viewDidDisappear instead, which you can rely on to be called when the view controller has been removed.

Upvotes: 1

Related Questions