Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A UIView that conforms
import UIKit
// Rather than a generic type with constraints on being a UIView and conforming to Extra
// you could do something like this.
protocol UIViewConvertable {
var uiview: UIView { get }
}
extension UIView : UIViewConvertable {
var uiview: UIView { return self }
}
protocol Extra {
func special()
}
class SpecialView : UIView, Extra {
func special() {}
}
let m: protocol<UIViewConvertable, Extra> = SpecialView()
@rayfix

This comment has been minimized.

Copy link
Owner Author

@rayfix rayfix commented Jul 1, 2015

Or...

import UIKit

protocol UIViewConvertable {
    var uiview: UIView { get }
}
extension UIView : UIViewConvertable {
    var uiview: UIView { return self }
}
protocol ExtraType {
    func special()
}

protocol SpecialViewType: UIViewConvertable, ExtraType {}

class SpecialView : UIView, SpecialViewType {
    func special() {}
}

let m: SpecialViewType = SpecialView()
@rayfix

This comment has been minimized.

Copy link
Owner Author

@rayfix rayfix commented Jul 1, 2015

Or even more streamlined...

import UIKit

protocol UIViewConvertable {
    var uiview: UIView { get }
}
extension UIView : UIViewConvertable {
    var uiview: UIView { return self }
}

protocol SpecialViewType : UIViewConvertable {
    func special()
}

class SpecialView1 : UIView, SpecialViewType {
    func special() { uiview.backgroundColor = .blackColor() }
}

let m: SpecialViewType = SpecialView1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment