SHARE
TWEET

Untitled

a guest Apr 20th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top