The File’s Owner object of a NIB file

I have a few questions regarding the proxy objects of a NIB file, specifically in regards to the File's Owner object.
  1. The File's Owner object is a placeholder instance which represents some instance of a class outside the NIB file that will soon substitute this tentative instance. From what I understand, NIB files and XIB files are lazy loaded. Does this mean the placeholder instance (before it is substituted by the "real" class's instance) is already an instance (not a type) even before the NIB files are called?

  2. What is this placeholder instance an instance of?

  3. The File's Owner object is configured with a custom class, say ViewController. Why do you have to specify the owner again when you load this NIB file? Bundle.main.loadNibNamed("SomeNIBFile", owner: self )

Answered by OOPer in 643790022

isn't Nuburg saying that File's Owner exists even before Bundle.main.loadNibNamed("SomeNIBFile", owner: self ) is executed?

NO. He is not.

You should better send some improvement request for that part to the author.
Substitute A for B means sort of "make A work as B" . It is not substitute A with B.

The part is saying that the nib-loading mechanism makes the real, already existing instance work as the nib owner object.
It is not saying the nib-loading mechanism substitutes some unspecified existing instance with the real, already existing instance.
File owner is the object that loads the xib. Usually, no need to set it in IB (stays as NSObject)

May have a look here, very detailed discussions:
https://stackoverflow.com/questions/34894563/whats-the-difference-between-custom-class-and-files-owner-setting-in-xib-file

https://stackoverflow.com/questions/15251370/what-is-the-files-owner-in-interface-builder

or possibly this:
http ://www.acttos. org/2016/08/What-does-Files-Owner-mean/

Does this mean the placeholder instance (before it is substituted by the "real" class's instance) is already an instance (not a type) even before the NIB files are called?

NO. Lazily loaded does not mean the placeholder is instantiated.

What is this placeholder instance an instance of?

It may change dynamically when loading the nib.

Why do you have to specify the owner again when you load this NIB file? Bundle.main.loadNibNamed("SomeNIBFile", owner: self )

Specifying the type of owner and specifying the exact instance of owner are different things.
For example, assume you specify the type of owner as ViewController, as you know, ViewController is a class and there may be many instances of it. You need to specify the exact one from the possibly many instances of ViewController.
Thank you for your answer, but I think @OOPer misunderstood my question. As far as I understand, the File Owner object is already an instance, not a type, when NIB is loaded. This is understandable because the entity that's going to substitute this File owner object is also an instance. But, at which point does this File Owner object get instantiated? Is it before NIB is loaded or after? NIB is lazy loaded, meaning it's only loaded when it is called by a certain instance, which means the order in which the File Owner object gets instantiated is either:
  1. NIB gets called and lazy loaded

  2. File Owner object gets instantiated

  3. The caller object substitutes the instance of the File Owner object

or
  1. File Owner object gets instantiated

  2. NIB gets called and lazy loaded

  3. The caller object substitutes the instance of the File Owner object

Also @OOPer mentioned that

It may change dynamically when loading the nib.

in regards to what the "type" of the File Owner object is. I'm aware that it eventually gets substituted by an instance of another type, but what I'm actually curious about is that since the File Owner object is already an instance as a placeholder, what is it an instance of prior to being substituted by something else?





@Ovis
Thanks for your reply.

because the entity that's going to substitute this File owner object is also an instance.

It cannot be the reason. As you know, you can replace nil with an instance. Or you may be using the word instance in some other ways?



@OOPer

It cannot be the reason. As you know, you can replace nil with an instance. Or you may be using the word instance in some other ways?

The point is, the File Owner object IS actually an instance. Are you saying it's not? I'm just curious as to the order in which it gets instantiated and what the type of it is.

Are you saying it's not? 

NO. It's not.

I'm just curious as to the order in which it gets instantiated and what the type of it is.

As you know, you pass an instance when you call Bundle.main.loadNibNamed("SomeNIBFile", owner: self ), File's owner is instantiated at the time self is instantiated, that's all.


Matt Neuburg provides his own definition in his book "iOS 14 Programming Fundamentals with Swift":

So what is the nib owner object? It’s a proxy representing an instance that already exists outside the nib at the time that the nib is loaded. When the nib is loaded, the nib-loading mechanism doesn’t instantiate that object; the nib owner is already an instance. Instead, the nib-loading mechanism substitutes the real, already existing instance for the nib owner object, using the real instance to fulfill any connections that involve the nib owner.



When the nib is loaded, the nib-loading mechanism doesn’t instantiate that object; the nib owner is already an instance.

Seems the book clearly says that the nib-loading mechanism doesn’t instantiate that object.
Have you refreshed your understanding properly?
Yes, but it seems like he's saying the nib-loading mechanism doesn’t instantiate that object because the nib owner is already an instance.

the nib owner is already an instance.

YES. When you call Bundle.main.loadNibNamed("SomeNIBFile", owner: self ), self -- the nib owner, is already an instance.
It sounds like it's all semantics at this point and the File's Owner is one and the same as the "self" that's calling the NIB. But, isn't Nuburg saying that File's Owner exists even before Bundle.main.loadNibNamed("SomeNIBFile", owner: self ) is executed?

Instead, the nib-loading mechanism substitutes the real, already existing instance for the nib owner object, using the real instance to fulfill any connections that involve the nib owner.

When A substitutes for B, A and B are separate entities (ex. I'm substituting stevia for sugar). "The real, already existing instance" is A, which is what you're referring to as "self" in your example. B is the nib owner object which exists as an instance prior to "self" replacing it.



Accepted Answer

isn't Nuburg saying that File's Owner exists even before Bundle.main.loadNibNamed("SomeNIBFile", owner: self ) is executed?

NO. He is not.

You should better send some improvement request for that part to the author.
Substitute A for B means sort of "make A work as B" . It is not substitute A with B.

The part is saying that the nib-loading mechanism makes the real, already existing instance work as the nib owner object.
It is not saying the nib-loading mechanism substitutes some unspecified existing instance with the real, already existing instance.
@OOPer
I've reached out to the author, but he never responded. Now that I revisit it though, I understand what you're saying and it makes sense to me. Thank you for the clarification.
The File’s Owner object of a NIB file
 
 
Q