Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift Weekly 11/22

Johnlin
November 22, 2016

Swift Weekly 11/22

Johnlin

November 22, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. SE-0145 Protocol બᎩੑ૬༰ extension Array: Equatable where Element: Equatable {

    static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool
 { ... } } ᙛArray தత౦੢ՄҎൺሣੋ൱૬౳࣌ɼṜछ Array ໵ՄҎൺሣ૬౳
  2. SE-0145 Protocol બᎩੑ૬༰ let a:[Int] = [1,2] let b:[Int] =

    [1,2] a == b //OK /// Returns `true` if these arrays contain the same elements. public func ==<Element : Equatable>(lhs: [Element], rhs: [Element]) -> Bool a ཫ໘తݩૉੋՄҎൺֱతIntɼ ॴҎ a ࿨ b ՄҎൺֱ
  3. SE-0145 Protocol બᎩੑ૬༰ 
 
 
 
 /// Returns `true`

    if these arrays contain the same elements. public func ==<Element : Equatable>(lhs: [Element], rhs: [Element]) -> Bool ca ཫ໘తݩૉੋෆೳൺֱతCatɼ ॴҎ ca ࿨ cb ෆೳൺֱ
  4. SE-0145 Protocol બᎩੑ૬༰ /// Returns `true` if these arrays contain

    the same elements. public func ==<Element : Equatable>(lhs: [Element], rhs: [Element]) -> Bool aa ཫ໘తݩૉੋՄҎൺֱత [Int] ୠੋ aa ࿨ bb ෆೳൺֱ ?!
  5. SE-0145 Protocol બᎩੑ૬༰ /// Returns `true` if these arrays contain

    the same elements. public func ==<Element : Equatable>(lhs: [Element], rhs: [Element]) -> Bool ၷݸ෺݅ೳෆೳൺֱੋ؃༗ᔒ༗૬༰ Equatable protocol public protocol Equatable { public static func ==(lhs: Self, rhs: Self) -> Bool } ༗ == function ୠੋᔒ༗એࠂ૬༰ Equatable ؐੋ။ඃᙛ੒ෆೳൺ ֱ
  6. SE-0145 Protocol બᎩੑ૬༰ extension Array: Equatable where Element: Equatable {

    static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool
 { ... } } ᙛArray தత౦੢ՄҎൺሣੋ൱૬౳࣌ɼṜछArray ໵ՄҎൺሣ૬౳ let aa:[[Int]] = [[1],[2]] let bb:[[Int]] = [[1],[2]] aa == bb //OK
  7. SE-0145 Protocol બᎩੑ૬༰ extension MyStruct: MyProtocol1 where GenericParameter: MyProtocol2 {

    func protocol1_function() } • ᙛMyStruct త GenericParameter ჩᏐ૬༰ MyProtocol2 ࣌ɼ MyStruct ब။૬༰ MyProtocol1
  8. SE-0145 Protocol બᎩੑ૬༰ • መࡍጯ༻ protocol Syncable { var json:String

    {get} func sync() } extension Syncable { func sync() {} // Default Impl } struct Menu : Syncable { internal var json: String } extension Array : Syncable where Element : Syncable { var json: String { ... } }
  9. ἷฏԽ㐲㐫 Class/Struct/Enum ఆٛ class A { let a:Int = 0

    class B { let b:Int = 0 class C { let c:Int = 0 } } }
  10. ἷฏԽ㐲㐫 Class/Struct/Enum ఆٛ class A { let a:Int = 0

    } extension A { class B { let b:Int = 0 } } extension A.B { class C { let c:Int = 0 } }