Created
November 14, 2017 00:47
-
-
Save mtfourre/d20f20a397832b7d3401a53f9f7b4149 to your computer and use it in GitHub Desktop.
Value of type 'UIView' has no member 'user'
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 | |
func bootstrap<T>(_ object: T?, with block: ((T?) -> T?)) -> T? { | |
return block(object) | |
} | |
protocol Nibbable { | |
} | |
extension Nibbable { | |
static var name: String { | |
return String(describing: type(of: self)).components(separatedBy: ".")[0] | |
} | |
static var nib: UINib { | |
return UINib(nibName: self.name, bundle: nil) | |
} | |
} | |
extension Nibbable where Self: UIResponder { | |
static func getRoot(withOwner owner: Any, options: [AnyHashable:Any]? = nil) -> Self? { | |
return self.nib.instantiate(withOwner: owner, options: options).first as? Self | |
} | |
} | |
class ContactDetailHeaderView: UIView, Nibbable { | |
var user: String? | |
} | |
class ContactDetailTableViewController: UITableViewController { | |
var user: String? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.backgroundView = bootstrap(ContactDetailHeaderView.getRoot(withOwner: self), with: { $0?.user = self.user }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment