2

What is meant by "File's Owner"? The XIB interface says it's UIApplication, but why is it named so? Which file does it own? I understand MVC to some extent, but I never heard of "File's Owner". What does it have to do with the controller of the application?

jscs
  • 63,694
  • 13
  • 151
  • 195
Vishwas
  • 1,533
  • 2
  • 19
  • 40
  • possible duplicate of [what actually is File Owner and First Responder in iPhone SDK - xCode?](http://stackoverflow.com/questions/3768602/what-actually-is-file-owner-and-first-responder-in-iphone-sdk-xcode) – jscs Mar 19 '12 at 20:32

1 Answers1

6

File's Owner is a proxy for the object that's specified as the owner when the .xib is loaded. Usually, it's the object that's actually loading the .xib. In any case, it's important to realize that File's Owner represents some object that's external to the objects in the .xib file, and as such it's basically the way that objects inside the .xib are connected to something outside the .xib and vice versa.

This all has very little to do with MVC and a lot to do with how Interface Builder works. Typically, you add IBOutlet properties and IBAction methods to the object that will load a .xib (such as an application delegate or a view controller). Then, using IB, you connect objects inside the .xib to the File's Owner proxy, and you set File's Owner as the target of your controls (choosing the appropriate action for the control).

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 1
    One place where this is important is if you are creating a `MainWindow` manually... I've had many memory-related errors from `nil` `self.window` from not setting File's Owner in `MainWindow` to `UIApplication` and connecting `Delegate` to the `AppDelegate` in the Interface Builder. – tacos_tacos_tacos Mar 19 '12 at 20:06