swift 2.0 大域関数の行方から #swift2symposium

73
EZNET 熊友宏 http://eznet.jp/ Swift 2.0 2015.06.28 @ Swift 2 (& LLDB) シンポジウム 域関数のから

Upload: tomohiro-kumagai

Post on 04-Aug-2015

2.821 views

Category:

Technology


0 download

TRANSCRIPT

1. EZ-NET http://ez-net.jp/ Swift 2.0 2015.06.28 @ Swift 2 (& LLDB) 2. EZ-NET http://ez-net.jp/ @es_kumagai Xcode 5 IP Phone with MOSA 3. Swift 2.0 4. 5. abs advance alignof alignofValue assert assertionFailure contains count debugPrint debugPrintln distance dropFirst dropLast dump enumerate equal extend fatalError filter find first flatMap getVaList indices insert isEmpty isUniquelyRefer enced isUniquelyRefer encedNonObjC join last lazy lexicographicalC ompare map max maxElement min minElement numericCast overlaps partition precondition preconditionFail ure prefix print println reduce reflect removeAll removeAtIndex removeLast removeRange reverse sizeof sizeofValue sort sorted splice split startsWith stride strideof strideofValue suffix swap toDebugString toString transcode underestimateC ount unsafeAddress Of unsafeBitCast unsafeDowncast unsafeUnwrap withExtendedLif etime withUnsafeMuta blePointer withUnsafeMuta blePointers withUnsafePoint er withUnsafePoint ers withVaList zip Swift 1.2 6. abs advance alignof alignofValue assert assertionFailure contains count debugPrint debugPrintln distance dropFirst dropLast dump enumerate equal extend fatalError filter find first flatMap getVaList indices insert isEmpty isUniquelyRefer enced isUniquelyRefer encedNonObjC join last lazy lexicographicalC ompare map max maxElement min minElement numericCast overlaps partition precondition preconditionFail ure prefix print println reduce reflect removeAll removeAtIndex removeLast removeRange reverse sizeof sizeofValue sort sorted splice split startsWith stride strideof strideofValue suffix swap toDebugString toString transcode underestimateC ount unsafeAddress Of unsafeBitCast unsafeDowncast unsafeUnwrap withExtendedLif etime withUnsafeMuta blePointer withUnsafeMuta blePointers withUnsafePoint er withUnsafePoint ers withVaList zip anyGenerator readLine Swift 2.0 7. ################################################################################# ++ ------------------------- 8. 9. contains count debugPrintln enumerate equal filter find first flatMap indices isEmpty last lexicographicalCompare map maxElement minElement partition println reduce reverse sorted startsWith toDebugString toString underestimateCount Swift 2.0 10. 11. 12. 13. 14. protocol CollectionType { typealias Element typealias Index : ForwardIndexType subscript(index:Index) -> Element { get } var startIndex:Index { get } var endIndex:Index { get } } Swift 1.2 15. func count(collection:T) -> T.Index.Distance { let start = collection.startIndex let end = collection.endIndex return distance(start, end) } Swift 1.2 16. 17. struct Month { var days:Array init(days:Int) { self.days = (1...days).map(Day.init) } } Swift 1.2 18. extension Month : CollectionType { subscript(index:Int) -> Day { return self.days[index - 1] } var startIndex:Int { return 1 } var endIndex:Int { return self.days.count + 1 } } Swift 1.2 19. 20. let june = Month(days: 30) // count(june) Swift 1.2 21. struct Year : CollectionType { : : } let year = Year(2015) // count(year) Swift 1.2 22. 23. 24. 25. 26. protocol CollectionType { } struct Array : CollectionType { } struct Dictionary : CollectionType { } Swift 1.2 27. func count(x:T) -> T.Index.Distance func indices(x:C) -> Range let array = Array() let dictionary = Dictionary() count(array) count(dictionary) Swift 1.2 28. Swift 1.2 29. struct Array : CollectionType { var count: Int { get } } Swift 1.2 func count(x:T) -> T.Index.Distance 30. array.count let c = count(array) let c = array.count Swift 1.2 31. Swift 1.2 32. Swift 2.0 33. 34. Swift 2.0 35. SequenceType contains enumerate filter flatMap lexicographicalCompare map maxElement minElement reduce reverse sorted startsWith underestimateCount MutableCollectionType partition CollectionType count first filter isEmpty last indexOf (find) indices String init: (toString) init:reflecting: (toDebugString) debugPrintln println Swift 2.0 36. Protocol Extension 37. Protocol Extension Swift 2.0 38. protocol CollectionType { typealias Element typealias Index : ForwardIndexType subscript(index:Index) -> Element { get } var startIndex:Index { get } var endIndex:Index { get } } Protocol Extension Swift 2.0 39. extension CollectionType { var count:Index.Distance { return distance(self.startIndex, self.endIndex) } var indices:Range { return self.startIndex ..< self.endIndex } } Protocol Extension Swift 2.0 40. struct Month : CollectionType { subscript(index:Int) -> Day { return self.days[index - 1] } var startIndex:Int { return 1 } var endIndex:Int { return self.days.count + 1 } } Protocol Extension Swift 2.0 41. let month = Month() month.count month.indices Protocol Extension Swift 2.0 42. 43. protocol CollectionType { typealias Element typealias Index : ForwardIndexType subscript(index:Index) -> Element { get } var startIndex:Index { get } var endIndex:Index { get } } Swift 1.2 // func count(x:T) -> T.Index.Distance { return distance(x.startIndex, x.endIndex) } func indices(x:C) -> Range { return x.startIndex ..< x.endIndex } // 44. protocol CollectionType { typealias Element typealias Index : ForwardIndexType subscript(index:Index) -> Element { get } var startIndex:Index { get } var endIndex:Index { get } } extension CollectionType { var count:Index.Distance { return distance(self.startIndex, self.endIndex) } var indices:Range { return self.startIndex ..< self.endIndex } } // Swift 2.0 45. Protocol Extension 46. let array = Array() array.count 1. Protocol Extension 47. extension CollectionType where Element : IntegerType { var total:Element { return self.reduce(0, combine:+) } } 2. Protocol Extension 48. let intArray = Array() let strArray = Array() intArray.total strArray.total 2. Protocol Extension 49. Protocol Extension 50. Protocol Extension 51. 52. Protocol Extension 53. Protocol Extension 54. Protocol Extension 55. 56. 1. // JSON Module protocol ValueType { } // XML Module protocol ValueType { } // struct JSONValue : JSON.ValueType { } 57. 2. protocol PNGType { var data:NSData{get} } protocol JPEGType { var data:NSData{get} } struct Picture : PNGType, JPEGType { // data var data:NSData { } } 58. 2. protocol PNGType { var pngData:NSData {get} } protocol JPEGType { var jpegData:NSData {get} } struct Picture : PNGType, JPEGType { // var jpegData:NSData { } } 59. 2. protocol PNGType { var data:PNGData {get} } protocol JPEGType { var data:JPEGData {get} } struct Picture : PNGType, JPEGType { // var data:PNGData { return } var data:JPEGData { return } } 60. struct Picture : ProtoA, ProtoB { 3. protocol ProtoA { typealias Element : protocol ProtoB { typealias Element : 61. 62. Protocol Extension 63. extension 64. Objective-C 65. Swift extension Objective-C 66. extension 67. Protocol Extension 68. Any AnyObject Protocol Extension ( Non-nominal type cannot be extended ) 69. Protocol Extension Swift 2.0 Protocol Extension func abs(x:T) -> T func advance (start:T, _ n:T.Distance) -> T 70. Protocol Extension stride Strideable Stride Protocol Extension func stride(from start:T, through end:T, by stride:T.Stride) -> StrideThrough 71. Protocol Extension Protocol Extension inout func removeAll (inout x:C, keepCapacity:Bool = default) 72. 73. Swift 2.0 Protocol Extension Protocol Extension Protocol Extension