Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Created January 13, 2022 02:12
Show Gist options
  • Save TuenTuenna/54bcd4b7984dac8510ccdf91ddbe9642 to your computer and use it in GitHub Desktop.
Save TuenTuenna/54bcd4b7984dac8510ccdf91ddbe9642 to your computer and use it in GitHub Desktop.
Nib 파일로 UIView 가져오기
import Foundation
import UIKit

extension UIView {
    
    class func fromNib(named: String? = nil) -> Self {
        let name = named ?? "\(Self.self)"
        guard let nib = Bundle.main.loadNibNamed(name, owner: nil, options: nil) else { fatalError("name Error") }
        guard let view = nib.first as? Self else { fatalError() }
        return view
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment