Skip to content

Instantly share code, notes, and snippets.

@bielikb
bielikb / Property Wrapper
Last active Sep 13, 2019
Use Autolayout
View Property Wrapper
@propertyWrapper
public struct UseAutoLayout<T: UIView> {
var value: T
public var wrappedValue: T {
get { return value }
set { self.value.translatesAutoresizingMaskIntoConstraints = false }
}
public init(wrappedValue: T) {
@bielikb
bielikb / UIView.swift
Last active Apr 20, 2018
Extension to load uiview from nib
View UIView.swift
extension UIView {
///
/// Loads a view from nib.
///
/// Please note that if you are assigning directly to an optinonal or unwrapped
/// optional you have to specify `name` of the nib.
///
class func loadFromNib<T>(_ name: String = String(describing: T.self), owner: AnyObject? = nil, options: [AnyHashable: Any]? = nil, bundle: Bundle? = Bundle.main) -> T {
return UINib(nibName: name, bundle: bundle).instantiate(withOwner: owner, options: options).first as! T
}
@bielikb
bielikb / UIDevice.swift
Last active Dec 7, 2017
UIDevice extension with model type - iPhone X support
View UIDevice.swift
extension UIDevice {
enum UIDeviceModelType : Equatable {
///iPhoneX
case iPhoneX
///Other models
case other(model: String)