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

Migrating to Swift 3 #kyoakiswift

Takaaki Tanaka
February 08, 2017

Migrating to Swift 3 #kyoakiswift

Kyobashi.swift x AKIBA.swift合同勉強会での発表資料です
#kyoakiswift

Takaaki Tanaka

February 08, 2017
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

  1. • ాத ޹໌ (Takaaki Tanaka) • Ϋϥεϝιουגࣜձࣾ • iOS ΞϓϦέʔγϣϯΤϯδχΞ

    • @kongmingtrap • iOS Developer (Swift / Objective-C) • GyazSquare / GitHub
  2. ͱ͋ΔΞϓϦ • Swift 1.1ͷࠒ͔Β࡞ΒΕ͍ͯΔΞϓϦ • ॳظόʔδϣϯ͸iOS 7ରԠ • Swift 1.2

    → 2.1ʹରԠ • ιʔείʔυɹ໿250ϑΝΠϧ • ϥΠϒϥϦ؅ཧ͸CocoaPods
  3. Swift 3.0 • NS Prefix͔Βͷ୤٫ → Ұ෦࢒Γ·ͨ͠ ʢNSNumberʣ • ৽ͨͳΔAPIσβΠϯΨΠυϥΠϯ

    → طଘ ͷϥΠϒϥϦͷϝιου໊มΘΓ͗͢ • ABI҆ఆԽ → Swift 4·Ͱ଴ͬͯͶ
  4. Swift 2.3 • Xcode 8 + iOS 10 SDKͰϏϧυ͕Մೳ •

    Swift 2.x ܥͷAPIσβΠϯ • ͱΓ͋͑ͣٸ͍ͰiOS 10ͰϏϧυ͠ͳ͚Ε ͹ͳΒͳ͍࣌ʹରԠ
  5. Swift 2.2΁ͷҠߦ • Xcode 7.2 + Swift 2.1 ͷ։ൃ؀ڥΛXcode 8.2

    Ͱىಈͨ͠ࡍɺʮEdit > Convert > To Current Swift Syntax.ʯͷର৅ʹTarget͕දࣔ ͞Εͳ͔ͬͨ • ͱΓ͋͑ͣɺXcode 7.3ͰSwift 2.1͔ΒSwift 2.2΁Ҡߦͨ͠
  6. Migration • Xcode 8.2Ͱىಈͨ͠ࡍɺաڈͷSwift όʔ δϣϯͷ৔߹͸Convertը໘͕ىಈ͢Δ • ʮEdit > Convert

    > To Current Swift Syntax.ʯ Ͱ΋࣮ߦՄೳ • Swift 1.1 → Swift 2.1ͷ࣌͸࢖͍ͷʹͳΒͳ ͔ͬͨ
  7. Migration • Xcode 8.2Ͱىಈͨ͠ࡍɺաڈͷSwift όʔδϣ ϯͷ৔߹͸Convertը໘͕ىಈ͢Δ • ʮEdit > Convert

    > To Current Swift Syntax.ʯͰ ΋࣮ߦՄೳ • Swift 1.1 → Swift 2.1ͷ࣌͸࢖͍΋ͷʹͳΒͳ ͔ͬͨ • Swift 2.2 → Swift 3.0ͷ࣌΋࢖͍΋ͷʹͳΒͳ ͔ͬͨ ← New!
  8. ͻͨ͢Β஍ಓͳ࡞ۀ • CurryԽͨ͠ϝιουͷमਖ਼ public static func log(level level: Level)(@autoclosure name:

    () -> String) (@autoclosure message: () -> String) -> String { if level.rawValue <= Logger.currentLevel.rawValue { let full = "\(level.description): \(name()) - \(message())" print(full) return full } return "" }
  9. ͻͨ͢Β஍ಓͳ࡞ۀ • CurryԽͨ͠ϝιουͷमਖ਼ public static func log(level: Level) -> ((@escaping

    () -> String) -> ((@escaping () -> String) -> String)) { return { (name: @escaping (() -> String)) in return { (message: @escaping (() -> String)) in if level.rawValue <= Logger.currentLevel.rawValue { let full = "\(level.description): \(name())) - \(message())" print(full) return full } return "" } } }