Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Migrate to Swift 3
Search
Francis Chong
July 14, 2016
Programming
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Migrate to Swift 3
Francis Chong
July 14, 2016
More Decks by Francis Chong
See All by Francis Chong
Implement beautiful DSL for iOS using Ruby
siuying
2
810
CocoaPods - A better way to use and publish open source project for Objective-C
siuying
2
390
Legco OpenData
siuying
0
140
EverClip - Evernote DEVCUP Meetup 2013 Hong Kong
siuying
0
100
iOS Development with Ruby using RubyMotion
siuying
1
200
Other Decks in Programming
See All in Programming
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
310
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
890
Android CLI
fornewid
0
220
Go 1.27 における memory allocation の高速化
andpad
0
150
メールのエイリアス機能を履き違えない
isshinfunada
0
230
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
550
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
270
テーブルをDELETEした
yuzneri
0
140
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
140
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
430
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
180
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
250
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.5k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
290
Being A Developer After 40
akosma
91
590k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Visualization
eitanlees
152
17k
How to build a perfect <img>
jonoalderson
1
5.9k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
480
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
350
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Transcript
MIGRATE TO SWIFT 3
FRANCIS CHONG @SIUYING
None
HTTPS://GETFINCH.ES
▸ Swift evolution ▸ What's new in Swift 3 ▸
Migration to Swift 3
SWIFT EVOLUTION
SWIFT 1
None
None
None
NSString* content = [[[listItemView text] text] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] let
content = listItemView.text.stringByTrimmingCharactersInSet( NSCharacterSet.whitespaceAndNewlineCharacterSet())
NEW LANGUAGE OPTIMIZED FOR EASY TRANSITION
SWIFT 2
SWIFT 2.0 ▸ Error Handling
SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension
SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension ▸ #available(iOS
9.0, *)
SWIFT 2.0 ▸ Error Handling ▸ Protocol Extension ▸ #available(iOS
9.0, *) ▸ nullability in UIKit/AppKit
SWIFT 2.2 ▸ #if(swift>=2.0)
SWIFT 2.2 ▸ #if(swift>=2.0) ▸ #selector
SWIFT 2.2 ▸ #if(swift>=2.0) ▸ #selector ▸ deprecated C style
loops
NEW IDEAS WITH COMPATIBILITY
SWIFT 3
WHAT'S NEW IN SWIFT 3
GRAND RENAMING
GRAND RENAMING ▸ API Design Guidelines
GRAND RENAMING ▸ API Design Guidelines ▸ Apply API Guidelines
to the Standard Library
GRAND RENAMING ▸ API Design Guidelines ▸ Apply API Guidelines
to the Standard Library ▸ Better Translation of Objective-C APIs Into Swift
FIRST PARAMETER // Swift 2 func moveToPoint(_: CGPoint) moveToPoint(point)
FIRST PARAMETER // Swift 2 func moveToPoint(_: CGPoint) moveToPoint(point) //
Swift 3 func move(to point: CGPoint) move(to: point)
CAPITALIZATION ON ENUM CASES // Swift 2 UIInterfaceOrientationMask.Landscape NSTextAlignment.Right
CAPITALIZATION ON ENUM CASES // Swift 2 UIInterfaceOrientationMask.Landscape NSTextAlignment.Right //
Swift 3 UIInterfaceOrientationMask.landscape NSTextAlignment.right
OMIT NEEDLESS WORDS // Swift 2 let content = listItemView.text.stringByTrimmingCharactersInSet(
NSCharacterSet.whitespaceAndNewlineCharacterSet())
OMIT NEEDLESS WORDS // Swift 2 let content = listItemView.text.stringByTrimmingCharactersInSet(
NSCharacterSet.whitespaceAndNewlineCharacterSet()) // Swift 3 let content = listItemView.text.trimming(.whitespaceAndNewlines)
MODERNIZED GCD // Swift 2 let queue = dispatch_queue_create("com.test.myqueue", nil)
dispatch_async(queue) { print("Hello World") }
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") }
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()
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() }
OPTIMIZED FOR ELOQUENT SWIFT
SHOULD I MIGRATE?
SHOULD I MIGRATE? ▸ New project
SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with
some Swift code?
SHOULD I MIGRATE? ▸ New project ▸ Objective-C project with
some Swift code? ▸ Swift 2 project with no Dependencies?
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?
WHAT VERSION SHOULD I MIGRATE?
YOU CANNOT MIXED SWIFT 2.2/2.3/3.0 IN SAME PROJECT
PRE MIGRATION
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"
ONLY UPDATE YOUR OWN PROJECT
MIGRATOR ▸ Rename Foundation classes ▸ Rename enum and static
names ▸ Rename methods and fields ▸ Replace changed code (Collection/Dispatch/CoreGraphics)
POST MIGRATION ▸ Fix compile error ▸ Read API Design
Guidelines ▸ Update to API Design Guidelines
POST MIGRATION ▸ Fix compile error ▸ Read API Design
Guidelines ▸ Update to API Design Guidelines
The End