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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
98
iOS Development with Ruby using RubyMotion
siuying
1
200
Other Decks in Programming
See All in Programming
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
190
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
160
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.8k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
780
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
300
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
750
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
0
120
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
1
420
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
My Coaching Mixtape
mlcsv
0
150
4 Signs Your Business is Dying
shpigford
187
22k
Designing for Performance
lara
611
70k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Skip the Path - Find Your Career Trail
mkilby
1
150
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Claude Code のすすめ
schroneko
67
230k
HDC tutorial
michielstock
2
720
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
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