title: How to call method in ViewController from viewmodel in swift?
body: <p>I am using MVVM design pattern in iOS project. I am trying to call method in viewcontroller from viewmodel.</p>
  
  <pre><code>import Foundation
  
  class NotificationViewModel {
  
      var onCompletion: ((_ success: Bool) -&gt; ())?
  
      func saveNotification(notification: Dictionary&lt;String, Any&gt;) {
          print("notification save")
          //other logic
          onCompletion?(true)
      }
     }
  </code></pre>
  
  <p>"saveNotification" method getting called from appdelegate when notification received</p>
  
  <pre><code>func userNotificationCenter(_ center: UNUserNotificationCenter,
                                  didReceive response: UNNotificationResponse,
                                  withCompletionHandler completionHandler: @escaping () -&gt; Void) {
          let userInfo = response.notification.request.content.userInfo
  
          guard
              let aps = userInfo[AnyHashable("aps")] as? NSDictionary,
              let alert = aps["alert"] as? NSMutableDictionary
              else {
                  // handle any error here
                  return
              }   
  
          NotificationViewModel().saveNotification(notification: alert as! Dictionary&lt;String, Any&gt;)
          }
  </code></pre>
  
  <p>trying to call method in viewcontroller when "saveNotification" trigger</p>
  
  <pre><code>     class AlertViewController: BaseViewController{
  
  
              var viewModel = NotificationViewModel()
  
              override func viewDidLoad() {
                  super.viewDidLoad()
  
                  self.viewModel.onCompletion = { success in
                      // this should be executed when `saveNotification()` will be called
  // **** this is never getting called ******
                      print("calling from viewmodel")
                      methodToCall()
                  }
              }
  
            func methodToCall(){
              //logic
            }
        }
  </code></pre>
  
  <p>But the method in viewdidload is not getting called anytime.</p>
  
  <p>Please suggest if its possible or any other way to achieve this?
  Thanks for help</p>