title: Cannot pass 'var' by 'init' into '@IBAction'
body: <p>I created a pair of xib file with the swift file(for that xib file).
  [xib_template.xib &amp; view_template.swift]
  And I want to control this pair of xib file by my [main_VC.swift].
  xib file have 1 button and 1 label.
  I want to change the text of label when I click this button.</p>
  
  <p>I want to set different template view and control them in my [main_VC].
  But the @IBAction seems independent inside the class</p>
  
  <p>I pass the value from [main_VC] to [view_template.swift] by init method searched on the internet.
  I can get correct value by using func in [main_VC].
  But when clicking the button,
  the value is always nil.
  The var inside IBAction cannot get the value from init.</p>
  
  <p>I am new in swift and I tried my best but still cannot fix this.
  How can I get the init value inside IBAction?
  Or how can I programmatically create &amp; disable the Ibaction from [main_VC]?</p>
  
  <p>I adjusted my code to be more easy to read.
  May have some little typing error.</p>
  
  <p>I searched online and tried all I can already.
  One people asked similar question before but have no answer.
  Hope for help.
  Thanks very much.</p>
  
  <p>[view_template.swift]</p>
  
  <pre><code>import UIKit
  
  class View_template_empty: UIView {
  
      var _uid: String?
      @IBOutlet weak var labellabel: UILabel!
  
      init (uid: String) {
              self._uid = uid
              super.init(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
      }
  
      required init?(coder aDecoder: NSCoder) {
      //        fatalError("init(coder:) has not been implemented")
          super.init(coder: aDecoder)
      }
  
      @IBAction func clickingPanel2(_ sender: Any) {
          print(self._uid)        // always nil !!!!!!
          self.labellabel.text = “test”
      }
  
      fun test () {
          print(self._uid)        // correct value
      }
  }
  </code></pre>
  
  <p>[main_VC] (only copy out the main function)</p>
  
  <pre><code>func allocator (_uid: String, uiView: UIView) {
      switch templateType {
          case “one”:
              if let loading_panels = Bundle.main.loadNibNamed("xib_template", owner: uiView, options: nil)?.first as? view_template {
                          loading_panels.translatesAutoresizingMaskIntoConstraints = false
                          uiView.addSubview(loading_panels)
  
                          loading_panels.leadingAnchor.constraint(equalTo: uiView.leadingAnchor).isActive = true
                          loading_panels.trailingAnchor.constraint(equalTo: uiView.trailingAnchor).isActive = true
                          loading_panels.bottomAnchor.constraint(equalTo: uiView.bottomAnchor).isActive = true
                          loading_panels.topAnchor.constraint(equalTo: uiView.topAnchor).isActive = true
  
              let view_temp = view_template(uid: _uid)
              view_temp.test()
              }
          case “two”:
              if let loading_panels = Bundle.main.loadNibNamed("xib_template_two”, owner: uiView, options: nil)?.first as? view_template_two {
                          loading_panels.translatesAutoresizingMaskIntoConstraints = false
                          uiView.addSubview(loading_panels)
  
                          loading_panels.leadingAnchor.constraint(equalTo: uiView.leadingAnchor).isActive = true
                          loading_panels.trailingAnchor.constraint(equalTo: uiView.trailingAnchor).isActive = true
                          loading_panels.bottomAnchor.constraint(equalTo: uiView.bottomAnchor).isActive = true
                          loading_panels.topAnchor.constraint(equalTo: uiView.topAnchor).isActive = true
              }
          default:
                      print("error")
  }
  </code></pre>