Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are File Owner and First Responder in iOS - Xcode?

What are File Owner and First Responder in iOS - Xcode?

like image 979
Matrix Avatar asked Sep 22 '10 11:09

Matrix


People also ask

What is file owner in Xcode?

The File owner is the object that loads the nib, i.e. that object which receives the message loadNibNamed: or initWithNibName: . If you want to access any objects in the nib after loading it, you can set an outlet in the file owner.

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.


1 Answers

The File Owner is an instantiated, runtime object that owns the contents of your nib and its outlets/actions when the nib is loaded. It can be an instance of any class you like - take a look at the identity tab of the tool palette.

File Owner is the main link between your application code and the contents of the nib file.

For example, consider you have a UIViewController subclass with an IBOutlet for a UILabel. In interface builder the File's owner will be set to the same class as your UIViewController. When your nib is loaded at runtime, the bindings of outlets and actions defined in your nib are bound to the instance of your view controller, as your view controller is the owner.

Nibs are loaded using:

[[NSBundle mainBundle] loadNibNamed:@"NibName" owner:nil options:nil]; 

The owner parameter is particularly important. That's the runtime instance of a class that owns the contents (outlets, actions and objects) of the nib being loaded.

Hopefully that's clear. To see this at work create a brand new iPhone project with a view controller. Open the Nib file and take a look at the identity tab.

First responder is simply the first object in the responder chain that can respond to events. The responder chain is a runtime collection (or more accurately a hierarchy) of objects that can respond to an event. For example, consider you have a window with a view and on that view is a text field.

If that text field has focus it's known as the first responder in the chain. So if you send a message to the first responder it'll be sent to the text field first. If the text field can't handle the message it'll be sent to the next responder. And the next. And the next, until you get to the end of the responder chain or something has consumed the event (iirc).

The responder chain is worth reading about - hit apple's documentation for more information.

like image 198
dannywartnaby Avatar answered Oct 17 '22 17:10

dannywartnaby