I am using xib file to load my view. So I am using loadNibNamed(_:owner:options:) method, this method return type is: [Any]?. As I understand it should return nil if something goes wrong, but when I am trying to load file that does't exist, my application terminates an exception. I thought that if there is no xib file with given name, loadNibNamed will return nil. So my question is: Is there any way to check that xib file exist through guard or if statements without getting exception from application?
So here is my code:
if let view = Bundle.main.loadNibNamed(name,
owner: self,
options: nil)?.first as? UIView {
return view
}
else {
fatalError("no file")
}