swift 1.2からswift 2への移行 #cocoa_kansai

Download Swift 1.2からSwift 2への移行 #cocoa_kansai

If you can't read please download the document

Upload: syo-ikeda

Post on 06-Aug-2015

1.113 views

Category:

Engineering


9 download

TRANSCRIPT

  1. 1. Swi$%1.2Swi$%2 @ikesyo 62#Cocoa,#2015,07,11#Sat #cocoa_kansai
  2. 2. @ikesyo iOS (Android) Swi$/Reac*veCocoa
  3. 3. Reac%veCocoa/Carthage (Collaborator)2
  4. 4. Swi$%1.2Swi$%2
  5. 5. !"Convert(to(Latest(Swi/(Syntax "" #"/
  6. 6. 1.#Convert#to#Latest#Swi1#Syntax count(String)"=>"String.characters.count "=>"Protocol"extensions : Printable"=>"CustomStringConvertible, DebugPrintable"=>"CustonDebugStringConvertible toString()"=>"String varlet do"=>"repeat NSErrorPointer"=>"throws
  7. 7. 9 Swi%&2&!
  8. 8. 2"swift2" !"""#
  9. 9. 9 di
  10. 10. Xcode&7GM
  11. 11. 2.# count(String)"=>"String.characters.count"//" String.CharacterView" =>"count/characters // Swift 1.2 extension String { var count: Int { return Swift.count(self) } var characters: String { return self } } "foo_bar".characters.count // => 7
  12. 12. 2.# Array"=>"Array"//"from"beta"3 =>"ArrayLiteralConvertible.Element" // Swift 1.2 extension Array { // Swift 2 `SequenceType` func flatMap(@noescape transform: (Element) -> U?) -> [U] }
  13. 13. 2.# Protocol(extensions =>(Array/Dictionary/Set/LazySequence/Optional SequenceType((CollectionType(Swi3(1.2 // Swift 1.2 let array = [ 1, 2, 3, 4, 5 ] // bad ! let r = map(filter(array) { $0 % 2 == 0 }) { String($0) } // => [ "2", "4" ] // good " let r = array.filter { $0 % 2 == 0 }.map { String($0) } // => [ "2", "4" ]
  14. 14. 2.# Printable/DebugPrintable#=>#CustomStringConvertible/ CustomDebugStringConvertible =>#typealias# // Swift 1.2 typealias CustomStringConvertible = Printable typealias CustomDebugStringConvertible = DebugPrintable struct FooBar: CustomStringConvertible { var description: String { ... } }
  15. 15. 2.# / Swi&'1.2:'2' #' Swi&'2:'2 '_' =>' =>'static =>'
  16. 16. 2.# / // before func globalFooBarFunc(a: String, b: Int) { ... } globalFooBarFunc("FooBar", 100) // after 1 func globalFooBarFunc(a: String, b bValue: Int) { ... } globalFooBarFunc("FooBar", b: 100) // after 2 final class FooBarUtil() { private init() {} static func fooBarMethod(a: String, b: Int) { ... } } FooBarUtil.fooBarMethod("FooBar", b: 100)
  17. 17. 2.# toString()"=>"String Int/UIntSwi-"1.2 Swi-"2:"String.toInt() -> Int?""Int.init?(_ text: String, radix: Int = default)" // Swift 1.2 let int: Int = 100 let uint: UInt = 12345 // bad ! let intString = toString(int) let uintString = toString(uint) // good " let intString = String(int) let uintString = String(uint)
  18. 18. 2.# !Swift2.swift! Xcode&7/Swi,&2&Convert to Latest Swift Syntax&OK
  19. 19. 3.#/ Protocol(extensions if/while/for do/try/catch guard defer Availability:(#available
  20. 20. 3.#/ // TODO: Swift 2 - guard if let value = optionalValue { ... ... ... ... ... } else { return nil }
  21. 21.