Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. //в самом контроллере регистрируем KVO обзервер, но не на себя, а на viewModel
  2. func registerWindowObserver() {
  3. self.addObserver(self.viewModel, forKeyPath: #keyPath(window), options: [.old, .new], context: nil)
  4. }
  5.  
  6. //внутри viewModel ловим это дело, проверяем наличие window и творим все свои непотребства
  7. override func observeValue(forKeyPath keyPath: String?,
  8. of object: Any?,
  9. change: [NSKeyValueChangeKey : Any]?,
  10. context: UnsafeMutableRawPointer?) {
  11.  
  12. if let keyPath = keyPath, keyPath == #keyPath(window),
  13. let newValue = change["new"] as? UIWindow {
  14.  
  15. //поехали всякое воротить
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement