# Chapter 2: Question about notification

**URL:** <https://forums.kodeco.com/t/chapter-2-question-about-notification/196662>\
**Category:** Combine: Asynchronous Programming with Swift\
**Created:** [September 30, 2023, 7:24am UTC](https://forums.kodeco.com/t/chapter-2-question-about-notification/196662 "2023-09-30T07:24:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![diuming](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/diuming/32/110937_2.png) [@diuming](https://forums.kodeco.com/u/diuming)\
**Post date:** [September 30, 2023, 7:24am UTC](https://forums.kodeco.com/t/chapter-2-question-about-notification/196662/1 "2023-09-30T07:24:21Z")

</div>

I do a simple notification test with combine.  
Click `postNotification` button in ViewController that received notification successful.  
Click `removeReceiver` button (set \_receive to nil) in ViewController that NotificationReceiver object never deinit. Why?  
Do I need to manual to cancel?

thanks

```auto
class NotificationReceiver {
    var _observer: AnyCancellable?
    
    deinit {
        print("[NotificationReceiver] deinit")
    }
    
    init() {
        _observer = NotificationCenter.default.publisher(for: .userClick, object: nil)
            .sink { notification in
                print("Received notification: \(notification)")
            }
    }
}

extension Notification.Name {
    static let userClick = Notification.Name("UserClick")
}

```

```auto
class ViewController: NSViewController {
    var _receiver: NotificationReceiver? = NotificationReceiver()
    
    @IBAction func postNotification(_ sender: Any) {
        NotificationCenter.default.post(name: .userClick, object: nil)
    }
    
    @IBAction func removeReceiver(_ sender: Any) {
        _receiver = nil
    }
}

```
