Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension for non reusable views #4

Closed
jakubvano opened this issue Jan 27, 2016 · 2 comments
Closed

Extension for non reusable views #4

jakubvano opened this issue Jan 27, 2016 · 2 comments

Comments

@jakubvano
Copy link
Contributor

I have been pointed to this lib after having created almost the same thing for one of our projects. I have done a couple of things differently, so I thought sharing them here might lead to a productive discussion:

public protocol Loadable {
    static var nib: UINib { get }
}

public protocol Reusable {
    static var reuseIdentifier: String { get }
}

public protocol LoadableCell: Reusable, Loadable {}

Having no direct relation between Loadable and Reusable allows for usage with UIViews designed in xib:

public extension Loadable where Self: UIView {
    static func loadFromNib() -> Self {
        return nib.instantiateWithOwner(nil, options: nil).first as! Self
    }
}

This is of course possible with NibReusable as well, but for simple loading of UIView from UINib name Loadable is a better fit.

Thoughts?

@AliSoftware
Copy link
Owner

That's actually a great idea. I'd love a PR doing that change!

@AliSoftware
Copy link
Owner

Closed by #5. Thx again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants