how to callback the array of data to another viewController in iOS Swift

In createCardVC, I have used the carbonKit library to show tab bar. Initially, the array of data loaded using static data but now I am trying to use an array of data from webView javascript postMessage.

  1. When createCardVC is loaded the carbonKit of the first tab is webViewVC will be loaded.
  2. In webView, From postMessage it will list number menu items to show tab bar menu.
  3. Here tabs values are dynamic and which will return from webView postMessage.

Here is the clear picture:

enter image description here

Here is the code createCardVC:

  override public func viewDidLoad() {
    super.viewDidLoad()

    carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: ["Basic Details"], delegate: self)
    carbonTabSwipeNavigation.insert(intoRootViewController: self, andTargetView: infoView)
    carbonTabSwipeNavigation.toolbar.barTintColor = UIColor.white
    carbonTabSwipeNavigation.setSelectedColor(UIColor.black)
    carbonTabSwipeNavigation.setIndicatorColor(UIColor(hexString: "#363794")) 

}//viewdidload

func onUserAction(data: String)
{
    print("Data received: (data)")
}


func sampleDelegateMethod(arg: Bool,completion: (Bool) -> ()){

    completion(arg)

    let singleTon = SingletonClass()
            print(singleTon.sharedInstance.dataText)
}


@IBAction func backBtn(_ sender: Any) {

   _ = navigationController?.popViewController(animated: true)
    navigationController?.setNavigationBarHidden(false, animated: true)
    tabBarController?.tabBar.isHidden = false


}



public init() {

         super.init(nibName: "CreateCardViewController", bundle: Bundle(for: CreateCardViewController.self))
     }

     required init?(coder aDecoder: NSCoder) {

         fatalError("init(coder:) has not been implemented")

     }

public func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {


    return firstView()

   }
func firstView() -> UIViewController {



    let cont = WebViewController()
    self.tabContView?.addChild(cont)
    self.tabContView?.view.addSubview(cont.view)

    cont.didMove(toParent: tabContView)
    let authToken = UserDefaults.standard.string(forKey: "authToken")

    cont.formKey = formKey
    print("cont vl", formKey ?? "")
    cont.processInstanceId = processInstanceId
    cont.authTokenValue = authToken
    cont.fullFormKey = fullFormKey
    cont.taskIdValue = TaskIdValue


    return cont

}

Here is the code for webView:

 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {

    if message.name == "jsHandler" {
       //  print(message.body)

    } else if message.name == "tabForm" {


        print("dynamic tabs value::::",message.body)

        let tabs = message.body
        let jsonString = JSONStringify(value: tabs as AnyObject)

            if let jsonData = jsonString.data(using: .utf8) {
              do {
                let decoder = JSONDecoder()
                let mainObject = try decoder.decode(DynamicTabsModel.self, from: jsonData)

                print("tab model:::", mainObject)

                createCardVC?.onUserAction(data: "The quick brown fox jumps over the lazy dog")
                delegate?.onPizzaReady(type: "Pizza di Mama")
                createCardVC?.sampleDelegateMethod(arg: true, completion: { (success) -> Void in

                    print("Second line of code executed")
                    if success { // this will be equal to whatever value is set in this method call

                        createCardVC?.onUserAction(data: "The quick brown fox jumps over the lazy dog")
                        delegate?.onPizzaReady(type: "Pizza di Mama")

                        let singleTon = SingletonClass()
                        singleTon.sharedInstance.dataText = "store data"

                        print("delegate method ::: true")


                    } else {
                         print("delegate method ::: false")
                    }
                })

                print("called delegate")

              } catch {

                print(error.localizedDescription)

              }
            }



    }
   }

My question is:

  1. How to return tab values from webView to CreateCardVC?
  2. How to show dynamic tabs in carbonKit?
  3. How to change dynamically ViewController for next tab using the same webViewController and url will return from webViewController.

Any help much appreciated pls…

Source: Ios