Created
July 1, 2015 15:44
-
-
Save rayfix/ea2595e5b1e123e849ec to your computer and use it in GitHub Desktop.
A UIView that conforms
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 | |
// 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() |
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
Or...