Created
August 13, 2016 03:57
-
-
Save ocwang/42f61358f947f4a24cceea2967d1bf60 to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
extension UIView { | |
class func toString() -> String { | |
let name = NSStringFromClass(self) | |
let components = name.componentsSeparatedByString(".") | |
guard let classString = components.last | |
else { fatalError("") } | |
return classString | |
} | |
class func ocw_nibNamed(nibName: String) -> UINib { | |
return UINib(nibName: nibName, bundle: NSBundle.mainBundle()) | |
} | |
class func ocw_nib() -> UINib { | |
return ocw_nibNamed(self.toString()) | |
} | |
class func ocw_instantiateWithNibNamed(nibName: String) -> AnyObject { | |
let nib = ocw_nibNamed(nibName) | |
let objects = nib.instantiateWithOwner(nil, options: nil) | |
guard let object = objects.first else { | |
fatalError("Error: couldn't create nib named \(nibName)") | |
} | |
return object | |
} | |
class func ocw_instantiateFromNib() -> AnyObject { | |
return ocw_instantiateWithNibNamed(self.toString()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment