title: Swift, how to call a function in other viewcontroller?
body: <p>My program has two controllers, CallerTableViewController, FunctionViewController</p>
  
  <p>Caller is in CallerTableViewController and the function is in FunctionViewController</p>
  
  <p>Now screen is displaying FunctionViewController while the calling program is in CallerTableViewController, the calling program should call the function in FunctionViewController</p>
  
  <p>How can I call the function which is displaying on screen?</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>this is actual program</p>
  
  <pre><code>import UIKit
  import CoreBluetooth
  
  class TableViewController: UITableViewController,
      CBCentralManagerDelegate,
      CBPeripheralDelegate {
  
      var centralManager:CBCentralManager!
      var connectingPeripheral:CBPeripheral!
  
      var bleDeviceName = [String]()
      var bleDevice=[CBPeripheral]()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let centralManager = CBCentralManager(delegate: self, queue: nil)
  
          centralManager.scanForPeripherals(withServices: nil, options: nil)
  
          self.centralManager = centralManager;
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  
      // MARK: - Table view data source
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return bleDevice.count
      }
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "oneCell", for: indexPath)
  
          cell.textLabel?.text = bleDeviceName[indexPath.row]
  
          return cell
      }
  
      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
  
          var peripheral=bleDevice[indexPath.row]
  
          self.centralManager.stopScan()
          connectingPeripheral = peripheral
          connectingPeripheral.delegate = self
          centralManager.connect(connectingPeripheral, options: nil)
  
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main)
      }
  
      func centralManagerDidUpdateState(_ central: CBCentralManager) {
          print("--- centralManagerDidUpdateState")
          switch central.state{
          case .poweredOn:
  
              let serviceUUIDs:[AnyObject] = [CBUUID(string: "1111")]
              let lastPeripherals = centralManager.retrieveConnectedPeripherals(withServices: serviceUUIDs as! [CBUUID])
  
              print(lastPeripherals.count)
  
              if lastPeripherals.count &gt; 0{
                  print("count&gt;0")
                  let device = lastPeripherals.last! as CBPeripheral;
                  connectingPeripheral = device;
                  centralManager.connect(connectingPeripheral, options: nil)
              }
              else {
                  centralManager.scanForPeripherals(withServices:nil, options: nil)
  
              }
          case .poweredOff:
              print("--- central state is powered off")
          case .resetting:
              print("--- central state is resetting")
          case .unauthorized:
              print("--- central state is unauthorized")
          case .unknown:
              print("--- central state is unknown")
          case .unsupported:
              print("--- central state is unsupported")
          }
      }
  
      func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
          print("--- didDiscover peripheral")
  
          if let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String{
  
              bleDevice.append(peripheral)
              bleDeviceName.append(localName)
              DispatchQueue.main.async{
                  self.tableView.reloadData()
              }
          }else{
              print("!!!--- can't unwrap advertisementData[CBAdvertisementDataLocalNameKey]")
          }
      }
  
      func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
          print("--- didConnectPeripheral")
  
          peripheral.delegate = self
          peripheral.discoverServices(nil)
          print("--- peripheral state is \(peripheral.state)")
      }
  
      func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
          if (error) != nil{
              print("!!!--- error in didDiscoverServices: \(error?.localizedDescription)")
          }
          else {
              print("--- error in didDiscoverServices")
              for service in peripheral.services as [CBService]!{
                  print("before disc chara"+service.uuid.uuidString)
                  if service.uuid.uuidString=="11111111-1111-11111111-1111111111111" {
                      peripheral.discoverCharacteristics(nil, for: service)
                      print("disc chara")
                  }
              }
          }
      }
  
      func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
          if (error) != nil{
              print("!!!--- error in didDiscoverCharacteristicsFor: \(error?.localizedDescription)")
          }
          else {
              print("found charact: service"+service.uuid.uuidString)
              if service.uuid == CBUUID(string: "11111111-1111-11111111-1111111111111"){
                  for characteristic in service.characteristics! as [CBCharacteristic]{
  
                      switch characteristic.uuid.uuidString{
  
                          case "00000000-0000-0000-0000-0000000000000":
                              print("Found Characteristic")
                              peripheral.setNotifyValue(true, for: characteristic)
  
                          default:
                              print()
                      }
  
                  }
              }
          }
      }
  
      func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
  
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
          //call function here
      }
  
  
  
  }
  </code></pre>
  
  <p>// this is the function in FunctionViewController</p>
  
  <pre><code>func printTextField() {
      print(textField.text)
  }
  </code></pre>