Created
January 13, 2020 14:36
-
-
Save letatas/8acb81b4b50caf1433fdca6eedde6899 to your computer and use it in GitHub Desktop.
ReusableXibViews - UIView extension to load xib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+Nib.swift | |
// ReusableXibViews | |
// | |
// Created by Matthias Lamoureux on 13/01/2020. | |
// Copyright © 2020 QSC. All rights reserved. | |
// | |
import UIKit | |
extension UIView { | |
/// Load the view from a nib file called with the name of the class | |
/// | |
/// - Note: The first object of the nib file **must** be of the matching class | |
static func loadFromNib() -> Self { | |
let bundle = Bundle(for: self) | |
let nib = UINib(nibName: String(describing: self), bundle: bundle) | |
return nib.instantiate(withOwner: nil, options: nil).first as! Self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment