Skip to content

Commit

Permalink
Fix bundle issue when installed with Carthage.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Feb 23, 2019
1 parent 74e10a2 commit 9b9ce09
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions CountryPickerView/NibView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ public class NibView: UIView {
}

fileprivate func loadViewFromNib() -> UIView {
let selfName = String(describing: type(of: self))
let podBundle = Bundle(for: type(of: self))
let nibBundleURL = podBundle.url(forResource: "CountryPickerView", withExtension: "bundle")!
let nibBundle = Bundle(url: nibBundleURL)
let nib = UINib(nibName: String(describing: type(of: self)), bundle: nibBundle)
let nibBundleURL = podBundle.url(forResource: selfName, withExtension: "bundle")!
var nibBundle = Bundle(url: nibBundleURL)
// The framework crashes if installed via Carthage because the nib
// file does not exist in the nibBundle but rather in the podBundle.
// This is a workaround.
if nibBundle?.url(forResource: selfName, withExtension: "nib") == nil {
nibBundle = podBundle
}
let nib = UINib(nibName: selfName, bundle: nibBundle)
let nibView = nib.instantiate(withOwner: self, options: nil).first as! UIView

return nibView
}

Expand Down

0 comments on commit 9b9ce09

Please sign in to comment.