Responsive Ad Area

Share This Post



I ran into the error code that haunts any apple developer today EXC_BAD_ACCESS .. After ample amounts of research , on different ways to debug etc I have landed here.

Turning on zombie objects in xCode showed me that the nil here guard let view = nib.instantiate(withOwner: self, options: nil).first as? T is causing my problem Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeec121e98)

Here is a look at the full file NibView.swift

//Joshua Paulsen - The Rise Collection

import UIKit

/// A base UIView subclass that instaniates a view
/// from a nib file of the same class name in order to
/// allow reusable views to be created.
internal protocol NibView where Self: UIView {


extension NibView {

    /// Initializes the view from a xib
    /// file and configure initial constrains.
    func xibSetup() {
        backgroundColor = .clear
        let view = loadViewFromNib()
        addEdgeConstrainedSubView(view: view)

    /// Loads a view from it's xib file.
    /// - Returns: an instantiated view from the Nib file of the same class name.
    fileprivate func loadViewFromNib<T: UIView>() -> T {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
        guard let view = nib.instantiate(withOwner: self, options: nil).first as? T else {
            fatalError("Cannot instantiate a UIView from the nib for class (type(of: self))")
        return view


Im new to messing around with nib views! looking for a fix here any help is appreciated.


Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar