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

Migrate to Swift 3

Migrate to Swift 3

Francis Chong

July 14, 2016
Tweet

More Decks by Francis Chong

Other Decks in Programming

Transcript

  1. NSString* content = [[[listItemView text] text] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] let

    content = listItemView.text.stringByTrimmingCharactersInSet( NSCharacterSet.whitespaceAndNewlineCharacterSet())
  2. GRAND RENAMING ▸ API Design Guidelines ▸ Apply API Guidelines

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

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

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

    NSCharacterSet.whitespaceAndNewlineCharacterSet()) // Swift 3 let content = listItemView.text.trimming(.whitespaceAndNewlines)
  6. 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") }
  7. 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()
  8. 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() }
  9. SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with

    some Swift code? ▸ Swift 2 project with no Dependencies?
  10. 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?
  11. 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"
  12. MIGRATOR ▸ Rename Foundation classes ▸ Rename enum and static

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

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

    Guidelines ▸ Update to API Design Guidelines