Last active
September 14, 2018 09:01
-
-
Save adiki/7de90e548b432809018dff64b0a245b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferencesBag { | |
private var references: [AnyObject] = [] | |
func append(_ reference: AnyObject) { | |
references.append(reference) | |
} | |
} | |
// For details about Token class please visit this address : | |
// https://github.com/objcio/S01E27-typed-notifications-part-1/blob/master/Typed%20Notifications%20(Part%201).playground/Pages/Typed%20Notifications%20(Part%201).xcplaygroundpage/Contents.swift | |
extension Token { | |
func disposed(by referencesBag: ReferencesBag) { | |
referencesBag.append(self) | |
} | |
} | |
class FeedViewController { | |
private let referencesBag = ReferencesBag() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupApplicationNotifications() | |
} | |
private func setupApplicationNotifications() { | |
NotificationCenter.default | |
.addObserver { [feedViewModel] (notification: ApplicationWillEnterForegroundNotification) in | |
feedViewModel.willEnterForeground() | |
} | |
.disposed(by: referencesBag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment