Skip to content

Instantly share code, notes, and snippets.

@Momachilles
Momachilles / UIView+Nib.swift
Created October 30, 2015 12:45
Load custom UIView from Nib in Swift using generics. Thanks to Logan (http://stackoverflow.com/users/2611971/logan)
class func fromNib<T : UIView>(nibNameOrNil: String? = nil) -> T {
let v: T? = fromNib(nibNameOrNil)
return v!
}
class func fromNib<T : UIView>(nibNameOrNil: String? = nil) -> T? {
var view: T?
let name: String
if let nibName = nibNameOrNil {
name = nibName