EBDOKUM EBDOKUM - 1 year ago 92
Swift Question

Cannot instantiate UIView from nib. "warning: could not load any Objective-C class information"

I get "could not load any Objective-C class information. This will significantly reduce the quality of type information available." warning in the console while initializing an instance of this class:

class SystemMessage: UIView{

@IBOutlet weak var lbl_message: UILabel!

var view: UIView!

override init(frame: CGRect) {
super.init(frame: frame)


required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)


func setup(){
view = loadViewFromNib()

view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

func loadViewFromNib() -> UIView{
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "SystemMessage", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

return view


Execution stops on line
let view = nib.instantiateWithOwner...
with "Thread 1: EXC_BAD_ACCESS(code=2...)"

What could be the possible reason behind this?

Answer Source

Found the solution. It all comes to understanding of how xibs work.

What I did was that I set class for both view and File's Owner and connected all the outlets from the View rather than from the File's owner.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download