Migrate to Swift 3

Migrate to Swift 3

Ecdf9a83234e21743d77b75fd308b929?s=128

Francis Chong

July 14, 2016
Tweet

Transcript

  1. MIGRATE TO SWIFT 3

  2. FRANCIS CHONG @SIUYING

  3. None
  4. HTTPS://GETFINCH.ES

  5. ▸ Swift evolution ▸ What's new in Swift 3 ▸

    Migration to Swift 3
  6. SWIFT EVOLUTION

  7. SWIFT 1

  8. None
  9. None
  10. None
  11. NSString* content = [[[listItemView text] text] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] let

    content = listItemView.text.stringByTrimmingCharactersInSet( NSCharacterSet.whitespaceAndNewlineCharacterSet())
  12. NEW LANGUAGE OPTIMIZED FOR EASY TRANSITION

  13. SWIFT 2

  14. SWIFT 2.0 ▸ Error Handling

  15. SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension

  16. SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension ▸ #available(iOS

    9.0, *)
  17. SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension ▸ #available(iOS

    9.0, *) ▸ nullability in UIKit/AppKit
  18. SWIFT 2.2 ▸ #if(swift>=2.0)

  19. SWIFT 2.2 ▸ #if(swift>=2.0) ▸ #selector

  20. SWIFT 2.2 ▸ #if(swift>=2.0) ▸ #selector ▸ deprecated C style

    loops
  21. NEW IDEAS WITH COMPATIBILITY

  22. SWIFT 3

  23. WHAT'S NEW IN SWIFT 3

  24. GRAND RENAMING

  25. GRAND RENAMING ▸ API Design Guidelines

  26. GRAND RENAMING ▸ API Design Guidelines ▸ Apply API Guidelines

    to the Standard Library
  27. GRAND RENAMING ▸ API Design Guidelines ▸ Apply API Guidelines

    to the Standard Library ▸ Better Translation of Objective-C APIs Into Swift
  28. FIRST PARAMETER // Swift 2 func moveToPoint(_: CGPoint) moveToPoint(point)

  29. FIRST PARAMETER // Swift 2 func moveToPoint(_: CGPoint) moveToPoint(point) //

    Swift 3 func move(to point: CGPoint) move(to: point)
  30. CAPITALIZATION ON ENUM CASES // Swift 2 UIInterfaceOrientationMask.Landscape NSTextAlignment.Right

  31. CAPITALIZATION ON ENUM CASES // Swift 2 UIInterfaceOrientationMask.Landscape NSTextAlignment.Right //

    Swift 3 UIInterfaceOrientationMask.landscape NSTextAlignment.right
  32. OMIT NEEDLESS WORDS // Swift 2 let content = listItemView.text.stringByTrimmingCharactersInSet(

    NSCharacterSet.whitespaceAndNewlineCharacterSet())
  33. OMIT NEEDLESS WORDS // Swift 2 let content = listItemView.text.stringByTrimmingCharactersInSet(

    NSCharacterSet.whitespaceAndNewlineCharacterSet()) // Swift 3 let content = listItemView.text.trimming(.whitespaceAndNewlines)
  34. MODERNIZED GCD // Swift 2 let queue = dispatch_queue_create("com.test.myqueue", nil)

    dispatch_async(queue) { print("Hello World") }
  35. MODERNIZED GCD // Swift 2 let queue = dispatch_queue_create("com.test.myqueue", nil)

    dispatch_async(queue) { print("Hello World") } // Swift 3 let queue = DispatchQueue(label: "com.test.myqueue") queue.async { print("Hello World") }
  36. MODERNIZED COREGRAPHICS // Swift 2 let ctx = UIGraphicsGetCurrentContext() let

    rectangle = CGRect(x: 0, y: 0, width: 512, height: 512) CGContextSetFillColorWithColor(ctx, UIColor.blueColor().CGColor) CGContextSetStrokeColorWithColor(ctx, UIColor.whiteColor().CGColor) CGContextSetLineWidth(ctx, 10) CGContextAddRect(ctx, rectangle) CGContextDrawPath(ctx, .FillStroke) UIGraphicsEndImageContext()
  37. MODERNIZED COREGRAPHICS // Swift 3 if let ctx = UIGraphicsGetCurrentContext()

    { let rectangle = CGRect(x: 0, y: 0, width: 512, height: 512) ctx.setFillColor(UIColor.blue().cgColor) ctx.setStrokeColor(UIColor.white().cgColor) ctx.setLineWidth(10) ctx.addRect(rectangle) ctx.drawPath(using: .fillStroke) UIGraphicsEndImageContext() }
  38. OPTIMIZED FOR ELOQUENT SWIFT

  39. SHOULD I MIGRATE?

  40. SHOULD I MIGRATE? ▸ New project

  41. SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with

    some Swift code?
  42. SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with

    some Swift code? ▸ Swift 2 project with no Dependencies?
  43. SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with

    some Swift code? ▸ Swift 2 project with no Dependencies? ▸ Swift 2 project with many external dependencies?
  44. WHAT VERSION SHOULD I MIGRATE?

  45. YOU CANNOT MIXED SWIFT 2.2/2.3/3.0 IN SAME PROJECT

  46. PRE MIGRATION

  47. MIGRATE YOUR DEPENDENCIES pod 'HidingNavigationBar', git: "https://github.com/siuying/HidingNavigationBar.git", branch: "swift3" pod

    'CocoaLumberjack/Swift', git: "https://github.com/siuying/CocoaLumberjack.git", branch: "xcode8" pod 'UIColor_Hex_Swift', git: "https://github.com:e-Sixt/UIColor-Hex-Swift.git", branch: "Swift-3.0" pod 'RxSwift', git: "https://github.com/ReactiveX/RxSwift.git", branch: "swift-3.0" pod 'RxDataSources', git: "https://github.com/siuying/RxDataSources.git", branch: "swift3" pod 'RxOptional', git: "https://github.com/RxSwiftCommunity/RxOptional.git", branch: "swift-3.0"
  48. ONLY UPDATE YOUR OWN PROJECT

  49. MIGRATOR ▸ Rename Foundation classes ▸ Rename enum and static

    names ▸ Rename methods and fields ▸ Replace changed code (Collection/Dispatch/CoreGraphics)
  50. POST MIGRATION ▸ Fix compile error ▸ Read API Design

    Guidelines ▸ Update to API Design Guidelines
  51. POST MIGRATION ▸ Fix compile error ▸ Read API Design

    Guidelines ▸ Update to API Design Guidelines
  52. The End