Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Last active November 24, 2015 17:39
Show Gist options
  • Save abbeyjackson/f7b5699bde02f3d664f2 to your computer and use it in GitHub Desktop.
Save abbeyjackson/f7b5699bde02f3d664f2 to your computer and use it in GitHub Desktop.
instantiate a xib / nib in Swift via an extension and add to a VC
//
// UIView+NibName.swift
// DrakeTaxEstimator
//
// Created by Kalan Stowe on 10/9/15.
// Copyright © 2015 DrakeTaxEstimator. All rights reserved.
//
import UIKit
extension UIView {
static func newViewWithNib() -> UIView {
let className = NSStringFromClass(self).componentsSeparatedByString(".").last!
let viewXib = NSBundle(forClass: self).loadNibNamed(className, owner: nil, options: nil)
return viewXib.first as! UIView
}
}
let footer = TaxEstimatorFooterView.newViewWithNib() as? TaxEstimatorFooterView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment