Xib and .swift - Which instance?


As the question says, if I have 2 files: a .xib (which is a view) and a .swift , which corresponds to that view. Which of the two is instantiated? In other words, who calls whom?.

asked by MatiEzelQ 11.04.2016 в 20:08

1 answer


You must be clear that strictly speaking only the classes are instantiated. A file .XIB is nothing more than a xml that relates some properties with a class to be able to access them.

Afterwards, a file with the extension .swift is not more than a text file, which may or may not contain the declaration of a class. Or put another way, not having a file .swift you can "instantiate" that file, because it can simply contain structures that you will not be able to instantiate in any way.

Finally, the most usual thing is that you instantiate a UIViewController which has an initializing method to which you pass as a parameter the corresponding .XIB to "marry" both files.

answered by 11.04.2016 в 21:18