Last active
September 12, 2015 14:16
-
-
Save MTattin/596abeddc8c3f7c9d9a0 to your computer and use it in GitHub Desktop.
swift2.0 Generics の優先順 ref: http://qiita.com/MTattin/items/51c11efba68f3e42e39d
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
protocol Count { | |
typealias CountType | |
var count: CountType{ get } | |
typealias BolType | |
var bl: BolType{ get } | |
} | |
class testVC: UIViewController, Count { | |
var num: Int = 30 | |
var count: Int { | |
return num | |
} | |
var truue: Bool = true | |
var bl: Bool { | |
return truue | |
} | |
func f<T:Any> (v:T) { print("Any \(v)") } | |
func f<T:UIView> (v:T) { print("UIView \(v)") } | |
func f<T:Count> (v:T) { print("Count \(v)") } | |
func f<T:UIViewController> (v:T) { print("UIViewController \(v)") } | |
func f<T:testVC> (v:T) { print("testVC \(v)") } | |
// Where制約(EquatableとComparableとHashable) | |
// Int(ComparableとHashable同時定義はエラー) | |
func fI<T:Count> (v:T) { print("I --- \(v)") } | |
func fI<T:Count where T.CountType: Comparable>(v:T) { print("I Comparable \(v)") } | |
func fI<T:Count where T.CountType: Equatable> (v:T) { print("I Equatable \(v)") } | |
func fJ<T:Count> (v:T) { print("J --- \(v)") } | |
func fJ<T:Count where T.CountType: Hashable> (v:T) { print("J Hashable \(v)") } | |
func fJ<T:Count where T.CountType: Equatable> (v:T) { print("J Equatable \(v)") } | |
func fK<T:Count> (v:T) { print("K --- \(v)") } | |
func fK<T:Count where T.CountType: Equatable> (v:T) { print("K Equatable \(v)") } | |
// Bool(Comparableは定義できないのでそれのみはエラー) | |
func fB<T:Count> (v:T) { print("B --- \(v)") } | |
func fB<T:Count where T.BolType: Hashable> (v:T) { print("B Hashable \(v)") } | |
func fB<T:Count where T.BolType: Equatable> (v:T) { print("B Equatable \(v)") } | |
func fB<T:Count where T.BolType: Comparable> (v:T) { print("B Comparable \(v)") } | |
func fC<T:Count> (v:T) { print("C --- \(v)") } | |
func fC<T:Count where T.BolType: Equatable> (v:T) { print("C Equatable \(v)") } | |
func fC<T:Count where T.BolType: Comparable> (v:T) { print("C Comparable \(v)") } | |
func fD<T:Count> (v:T) { print("D --- \(v)") } | |
func fD<T:Count where T.BolType: Comparable> (v:T) { print("D Comparable \(v)") } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let v1: UIView = self.view | |
let v2: UIView = UIView() | |
f(self) | |
f(UIViewController()) | |
f(self.view) | |
f(v1) | |
f(v2) | |
f() | |
fI(self) | |
fJ(self) | |
fK(self) | |
fB(self) | |
fC(self) | |
fD(self) | |
} | |
} | |
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
testVC <SymPlayer.testVC: 0x7f9961a4ab00> | |
UIViewController <UIViewController: 0x7f99605b3400> | |
Any <UIView: 0x7f99605b0aa0; 省略> | |
UIView <UIView: 0x7f99605b0aa0; 省略> | |
UIView <UIView: 0x7f9960547520; 省略> | |
Any () | |
I Comparable <SymPlayer.testVC: 0x7f87c250cee0> | |
J Hashable <SymPlayer.testVC: 0x7f87c250cee0> | |
K Equatable <SymPlayer.testVC: 0x7f87c250cee0> | |
B Hashable <SymPlayer.testVC: 0x7f87c250cee0> | |
C Equatable <SymPlayer.testVC: 0x7f87c250cee0> | |
D --- <SymPlayer.testVC: 0x7f87c250cee0> |
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
var view: UIView! |
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
let v3: UIView? = UIView() | |
let v4: UIView! = UIView() | |
f(v3) | |
f(v4) | |
f(v3 as UIView!) | |
f(v4 as UIView) |
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
Any Optional(<UIView: 0x7fc0195efe20; 省略>) | |
Any <UIView: 0x7fc0195c9290; 省略> | |
Any <UIView: 0x7fc0195efe20; 省略> | |
UIView <UIView: 0x7fc0195c9290; 省略> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment