Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adiki
Last active September 14, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiki/7de90e548b432809018dff64b0a245b6 to your computer and use it in GitHub Desktop.
Save adiki/7de90e548b432809018dff64b0a245b6 to your computer and use it in GitHub Desktop.
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