Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the need of File's owner in xcode xib files? Can i do the same things without file's owner?

Why should I set File's Owner's Class Identity rather than the Class Identity of my custom object that is shown in the nib and make the connections from it? What happens if I set file's owner to nil? To me everything works fine with nil file's owner so what is the deference in doing the connection from it?

like image 921
Marios Mourelatos Avatar asked Jun 03 '12 19:06

Marios Mourelatos


People also ask

What is file owner in Swift?

The File Owner proxy is an Interface Builder construct to represent potential instances of objects that will instantiate an instance of the object graph that allows the user to connect action methods and outlets defined in the object graph to the File Owner instance that loads the NIB/XIB (again, there can be more than ...

What are XIB files used for?

What are XIB files? From the point of view of the UI designer, XIB files contain the views or windows that you design in Interface Builder – the controls, their layout and properties, and their connections to your code. It is important to understand that on a technical level, XIB files are stored object graphs.

What is file's owner?

Initially, a file's owner is identified by the user ID of the person who created the file. The owner of a file determines who may read, write (modify), or execute the file.

What is file's owner in Xcode?

About the File's Owner One of the most important objects in a nib file is the File's Owner object. Unlike interface objects, the File's Owner object is a placeholder object that is not created when the nib file is loaded. Instead, you create this object in your code and pass it to the nib-loading code.


2 Answers

A NIB represents an archived object graph. You can load it and that object graph will be reconstituted. The thing, you usually want/need the newly-loaded object graph to be hooked into the already-existing object graph of your program. You don't want it to be standing apart, disconnected from everything else.

There are a few ways that the newly-loaded object graph can get connected to the rest of the program's object graph. One way is the set of proxy objects available in a NIB. There's one for the application object. Another such proxy object is File's Owner. A proxy object is a thing which has a representation in the NIB but is not actually contained in the NIB. Unlike the other objects in the NIB, the objects represented by the proxies are not created when the NIB is loaded, they exist before the NIB is loaded. The proxies allow connections between these pre-existing objects and the objects in the NIB. That's how the new object graph from the NIB can be connected to the existing object graph of your program.

The MainMenu NIB is unusual. It is automatically loaded at application startup by Cocoa, which means there isn't (can't be, really) much in the way of pre-existing objects. That NIB also usually contains an instance of the app delegate, which is a kind of coordinating controller. Usually, though, other types of NIBs would not contain coordinating controllers. (They do contain mediating controllers, like NSArrayController, but that's different.) Rather, coordinating controllers are typically created in code and, often, they are responsible for loading NIBs.

For example, you would use an NSWindowController as the coordinating controller for a window. The window would be defined in a NIB. The window controller would be instantiated in code – whichever code decides that a window should be created – and it would load the NIB. It would be the File's Owner of the NIB, too. It would manage the window and the top-level objects of the NIB.

If you are setting the File's Owner to nil, then a) you probably are dealing with very simple NIBs at this point, and b) you may be leaking top-level objects from the NIBs that you load.

like image 80
Ken Thomases Avatar answered Nov 15 '22 05:11

Ken Thomases


File's owner is the file that contains all the IBOutlets and IBActions for that view. For example, if you have a class "ViewController" and it contains an IBOutlet UIButton *button and -(IBAction)changeViewWhenButtonPressed: (id) sender, the only way you can connect the outlet and action is through setting "ViewController" as your view's File's Owner.

I am relatively certain that Class Identity is synonymous with File's Owner.

Also, these links might be helpful:

What are File Owner and First Responder in iPhone SDK - xCode?

File's Owner Definitions

What is File's Owner

like image 36
pasawaya Avatar answered Nov 15 '22 04:11

pasawaya