Share
Embed
Swift Weekly 11/22
Johnlin
November 22, 2016
Transcript
14 slides
-
SE-0145 Protocol બᎩੑ૬༰ extension Array: Equatable where Element: Equatable {
static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool { ... } } ᙛArray தత౦ՄҎൺሣੋ൱૬࣌ɼṜछ Array ՄҎൺሣ૬ -
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 ՄҎൺֱ -
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 ෆೳൺֱ -
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 ෆೳൺֱ ?! -
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 ؐੋ။ඃᙛෆೳൺ ֱ -
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 -
SE-0145 Protocol બᎩੑ૬༰ extension MyStruct: MyProtocol1 where GenericParameter: MyProtocol2 {
func protocol1_function() } • ᙛMyStruct త GenericParameter ჩᏐ૬༰ MyProtocol2 ࣌ɼ MyStruct ब။૬༰ MyProtocol1 -
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 { ... } } -
ἷฏԽ㐲㐫 Class/Struct/Enum ఆٛ class A { let a:Int = 0
class B { let b:Int = 0 class C { let c:Int = 0 } } } -
ἷฏԽ㐲㐫 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 } }