Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load NIB from my own Pod

I have a CalendarCell.xib and a CalendarCell.swift UIView subclass in my Pod framework. CalendarCell.swift has outlets connected to its view. At runtime I get this error:

Could not load NIB in bundle: 'NSBundle (loaded)' with name 'CalendarCell'

In my podspec file I created a bundle resource:

s.resource_bundles = { 'Resources' => ['MyFramework/**/*.{xib,xcassets}'] }

If I install my Pod I can see the xib file but it crashes and now it seems that the xib file and its swift counterpart are in different bundle.

Any help would be appreciated!

like image 232
Herczeg Ádám Avatar asked Dec 07 '22 19:12

Herczeg Ádám


1 Answers

You're right, the xibs are stored in a different bundle. You need to find the path of the xibs bundle and load all the xibs from that bundle, instead of loading them from the main bundle.

To find the path of the bundle, in Swift 3:

let bundle = Bundle(for: YourClass.self)

So, you have to load your UINib from that bundle:

let nib = UINib(nibName: "YourXibName", bundle: bundle)

and register it to your UITableView/UICollectionView, if you need it for this purpose:

self.tableView.register(nib, forCellReuseIdentifier: "cellIdentifier")
like image 55
Nicola Giancecchi Avatar answered Dec 30 '22 10:12

Nicola Giancecchi