ios - How to declare weak notification -


maybe title not provide description please read following.

i have notification set listen event:

nsnotificationcenter.defaultcenter().addobserver(self, selector: #selector(self.checkifnotificationswereturnedonafteralertshowing), name: uiapplicationwillenterforegroundnotification, object: uiapplication.sharedapplication()) 

then want remove observer on notification. found need use deinit this:

deinit  {      nsnotificationcenter.defaultcenter().removeobserver(uiapplicationwillenterforegroundnotification)     print("deinit") } 

but problem when close view controller, program never executes deinit function. in answer found due strong reference.

i checked many links not able find how declare weak reference notification. how can declare weak notification?

hope question clear.

looking forward help.

i not able find way handle deinit decided remove observer in viewwilldisappear worked me. suggested rob napier in comment above


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -