return value to controller caller

Controller A open Controller B
After Controller B close, b return a value to A

1. Declare a protocol in A or B

protocol SearchPartProtocol{
     func ReturnValue(value: [PartItem])

}

2. Controller A implement the protocol

Class ControllerA: UIViewController, SearchPartProtocol
{

    var  variableReceiveReturnValue :  [PartItem] = []
....
// MARK - SearchPartProtocol
   func ReturnValue(value: [PartItem])
  {
       variableReceiveReturnValue = value
  }
....
}

3. In Controller B, declare a var delegate:
Class ControllerB: UIViewController
{
    var delegate : SearchPartProtocol?

   func viewDidLoad()
  {
     
   }
   func viewWillDisappear(_ animated: bool)
  {
         if delegate != nil{
               delegate.ReturnValue(value: valueNeedToBeReturn)
        }
  }
}

4. Back to ControllerA, in the method where to open ControllerA:
   
     controllerB.delegate = self




Comments

Popular posts from this blog

Apple Push Notification Service APNS

Delivery In House iOS app