猫·仁波切

会研发的PM才是好OP.

Swift Special Protocols

via WWDC 404

Protocols are your hooks into the Swift core language Swift generics combine abstraction, safety, and performance in new ways Read, experiment, and have fun. There’s plenty to discover!

LogicValue // 重载 if val

Printable // 重载 println

1
2
3
protocol Printable {
    var description: String { get }
}

Sequence // 重载 for-in

1
2
3
4
5
6
7
8
9
protocol Sequence {
  typealias GeneratorType : Generator
  func generate() -> GeneratorType
}

protocol Generator {
  typealias Element
  mutating func next() -> Element?
}
1
2
3
4
5
// for .. in { }
var __g = someSequence.generate()
while let x = __g.next() {
    ...
}}

*Convertible

  • IntegerLiteralConvertible
  • FloatLiteralConvertible
  • StringLiteralConvertible
  • ArrayLiteralConvertible
  • DictionaryLiteralConvertible

Equatable

==

Comments