-1

I shifted to swift3 a little while ago. Even after converting to swift3, the notification center code below was working fine (no crashes and doing what it was supposed to).

I was experimenting with force touch in some other parts of the code when suddenly the app started crashing (SIGBRT...'unrecognized selector' sent).

 NotificationCenter.default.addObserver(self, selector: Selector(("applicationWillEnterBackGround:")), name: Notification.Name.UIApplicationDidEnterBackground, object: nil)

Cleaned the build, ran it again. Not sure what might be causing this ? Still pretty new to Swift, any help is greatly appreciated :)

Thanks, Karthik

1 Answers1

1

The problem is the capital G in Selector(("applicationWillEnterBackGround:")).

But why on earth are you even writing code like this? Use #selector syntax; its whole purpose is to prevent this sort of silliness.

Also, you never being doing anything to call applicationWillEndBackground. That is something only the runtime calls. You have no right to configure a notification like this.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks Matt. I switched to #selector syntax and it works fine. I actually understand how it's working now!. Thanks for the hint. I am not doing anything with the application entering background - that was just for example/debug. I am doing some stuff when the app enters foreground. – karthik sarpatwari Oct 02 '16 at 01:01
  • @karthiksarpatwari see [here](http://stackoverflow.com/a/36211714/5175709) – mfaani Oct 05 '16 at 16:40