Skip to content

Instantly share code, notes, and snippets.

@olxios
Last active June 21, 2019 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olxios/335668667643a59c0b6f5986bb6bf46f to your computer and use it in GitHub Desktop.
Save olxios/335668667643a59c0b6f5986bb6bf46f to your computer and use it in GitHub Desktop.
// Swift 3
import UIKit
class TestView: UIView {
// MARK: Observers
override func didMoveToWindow() {
if self.window != nil {
NotificationCenter.default.addObserver(self, selector: #selector(test(_:)), name: NSNotification.Name(rawValue: "TestNotification"), object: nil)
}
}
override func willMove(toWindow newWindow: UIWindow?) {
if newWindow == nil {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "TestNotification"), object: nil)
}
}
// MARK: Actions
func test(_ notification : Notification) {
print("Test")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment