What's the difference between custom class and file's owner setting in xib file?

IosInterface BuilderXib

Ios Problem Overview


In a custom xib file, what's the difference between the two following setting methods shown in the images below? enter image description here

enter image description here

Ios Solutions


Solution 1 - Ios

please check this link : What is the File's Owner (in Interface builder)? confused difference between Custom Class for an Object and for the File's Owner and steps via IB

in first screen shot : you should set the custom class of your View .

and in the second screen shot (files owner) you can Set the file's owner to your UIView subclass so that you can connect outlets to it

Solution 2 - Ios

When you add custom UIView with XIB you init this custom view in some UIViewController and write:

let nib = UINib(nibName: "CardView", bundle: nil)
let view = nib.instantiate(withOwner: self, options: nil).first as! CardView

File's owner (in withOwner: parameter) this is usually owner is a ViewController where you add your custom UIView

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlfyView Question on Stackoverflow
Solution 1 - IosMo FarhandView Answer on Stackoverflow
Solution 2 - IosZhanserikView Answer on Stackoverflow