Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object vs. External Object in XCode Interface Builder

What is the difference between Object and External Object in the IB?
When should I use each?

like image 571
RCB Avatar asked Feb 28 '13 19:02

RCB


2 Answers

Adding on to the other answer: You could use an 'External Object' to access a common object across multiple xib's. You could do this in other ways too, but this would be convenient.

Like for example, if you have a 'big' action to be performed for button clicks over multiple xib's and if you have many such actions (and additionally if it's the same data you are performing this action on), instead of calling addTarget:action... , you could create the proxy object of this class and wire it up to the buttons.

You can connect the proxy object to your xib using the following code:

 id *proxy = <someObject>; //The object you want to wire up
//In the below line of code use the same key as the identifier you give for the proxy object in the Interface Builder
 UINib *nib = [UINib nibWithNibName:@"ViewController" bundle:Nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:proxyObject,@"proxy", nil];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:dict,UINibExternalObjects, nil];
NSArray  *nibArray = [nib instantiateWithOwner:self options:dict2];
self.view = [nibArray objectAtIndex:0];
like image 95
Rakesh Avatar answered Nov 07 '22 22:11

Rakesh


An Object is something that's actually embedded in the nib.

An External Object is one that the code that loads the nib promises to provide at load time (I believe via a dictionary that maps keys to external objects).

Most people never use any External Object besides File's Owner (which is already provided for you). You almost certainly just want Objects.

like image 31
Lily Ballard Avatar answered Nov 07 '22 20:11

Lily Ballard