Last active
October 19, 2019 03:37
-
-
Save pofat/70e190aede0e786421ec87157e7408d8 to your computer and use it in GitHub Desktop.
PAT 好讀版
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
// 有 associatedtype 的 protocol | |
public protocol IteratorProtocol { | |
associatedtype Element | |
mutating func next() -> Element? | |
} | |
// 有 Self 的 protocol, Hashable 的 Self 來自所繼承的 Equatable | |
public protocol Hashable: Equatable { | |
var hashValue: Int { get } | |
func hash(into hasher: inout Hasher) | |
func _rawHashValue(seed: Int) -> Int | |
} | |
public protocol Equatable { | |
static func == (lhs: Self, rhs: Self) -> Bool | |
} | |
// 以下寫法都會被 compiler 抱怨 | |
// Protocol XXX can only be used as a generic constraint because it has Self or associated type requirements | |
func generateDictionaryKey() -> Hashable { | |
return 8 | |
} | |
func getIterator() -> IteratorProtocol { | |
return ["1", "2", "3"].makeIterator() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment