5

It's some time Apple has provided us with storyboards, I'm following its' evolution since the very beginning, it has some pros and cons, but for sure this is a "future" if you compare it to the oldschool "xib" files...

What I'm aware of here is something called "External Object". When using standard "xibs" we are always able to drag&drop two special kind of objects from IB object library (right side pane)

"File's Owner" is an example of this "External object".

We were able to drag&drop one more ExternalObject to our xib file and hook it up to some external object by instantiating such ViewController using this UINib API:

- (NSArray *)instantiateWithOwner:(id)ownerOrNil options:(NSDictionary *)optionsOrNil;

... yes it was possible, documentation:

If the nib file contains any proxy objects beyond just the File’s Owner proxy object, you can specify the runtime replacement objects for those proxies using the options dictionary. In that dictionary, add the UINibExternalObjects key and set its value to a dictionary containing the names of any proxy objects (the keys) and the real objects to use in their place. The proxy object’s name is the string you assign to it in the Name field of the Interface Builder inspector window.

Now when it comes to storyboards - External Objects are not available in the objects inspector. That would make sense because I haven't found any API that would allow us to inject external objects into a view controller created from storyboard. We only have this:

- (id)instantiateInitialViewController;

- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier;

So there is no way to pass our "options".

However...

External Object is not available in storyboard until... you make a Swift project (maybe there is another factor that enables External Object in my storyboard, I'm not sure).

So it is possible to have a setup where storyboards allow us to drag & drop External Object into a storyboard. But how can we then take advantage of this? How can I load a view controller from storyboard and hook up these proxy objects?

ravron
  • 11,014
  • 2
  • 39
  • 66
kprofic
  • 51
  • 2

1 Answers1

2

You can drag&drop an NSObject on a view controllers scene and give it the right class in the inspector.

enter image description here

it can be wired up as expected

enter image description here

I created a Example Project for this question/answer and published it at GitHub.

Community
  • 1
  • 1
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • 2
    I'm sorry but this is not an answer for my question, I know I can use "NSObject" is storyboard - it is called Object in IB inspector. Im asking about a thing called "External Object" in IB inspector. Bests! – kprofic Jan 23 '15 at 09:06
  • This can represent anything. – vikingosegundo Jan 23 '15 at 12:21
  • 2
    Yes that's true it may be any object but this object will be created during xib unarchivisation. External Object on the other hand is not created in this process it is a link to some other object that already exists. – kprofic Jan 23 '15 at 13:56
  • make it an NSProxy object and load it when needed. – vikingosegundo Jan 23 '15 at 14:28
  • Pretty neat idea, I will give it a try. – kprofic Jan 24 '15 at 20:50