title: Swift 3 - Access Variable From Instance Of XIB In Another Class
body: <p>I have been trying to figure this out for days and haven't had much luck :(</p>
  
  <p>What I want to do is set the variable inside of an instance of a XIB (called BottomNav) that already exists in another ViewController, called "curX". I have come the closest with the following:</p>
  
  <pre><code>class Util: NSObject {
      class func loadNib() {
          let nib: BottomNav = Bundle.main.loadNibNamed("BottomNav", owner: self, options: nil)!.first as! BottomNav
          nib.curX = 10
      }
  }
  </code></pre>
  
  <p>Here is the BottomNav Class:</p>
  
  <pre><code>class BottomNav: UIView {
      @IBOutlet var view: UIView!
      @IBOutlet weak var homeBtn: UIView!
      @IBOutlet weak var scroller: UIScrollView!
      @IBOutlet weak var scrollerContent: UIView!
  
      var curX = 32
  
      required init(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)!
  
          Bundle.main.loadNibNamed("BottomNav", owner: self, options: nil)
          self.addSubview(self.view)
      }
  
  }
  </code></pre>
  
  <p>This passes the compiler with no warnings, but when it's ran I get a "this class is not key value coding-compliant for the key" error. This usually appears when there's an outlet that no longer exists, but this is definitely not the case, I've tested it with multiple XIBs that are already on the app, and had no problem loading in the first place via storyboards. I only get this error with "loadNibNamed".</p>
  
  <p>Am I even on the right path here? My thought is maybe my Util class doesn't have access to Bundle or something?</p>