Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. extension Publisher where Failure == Never{
  2. func present<ToVC:UIViewController, P>(from fromVC:UIViewController,
  3. to toVC:ToVC,
  4. assignee: KeyPath<ToVC, P>,
  5. keyPath: ReferenceWritableKeyPath<P,Output>,
  6. animated:Bool = true) -> AnyCancellable {
  7. sink {[weak fromVC, weak toVC] (output) in
  8. guard let to = toVC, let from = fromVC else {return}
  9. let toBeAssign = to[keyPath: assignee]
  10. toBeAssign[keyPath: keyPath] = output
  11. from.present(to, animated: true, completion: nil)
  12. }
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement