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開発
kotaminato
1
120
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
0
230
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
300
AIが無かった頃の素敵な出会いの話
codmoninc
1
140
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
3
1.6k
Claude Team Plan導入・ガイド
tk3fftk
0
220
Foundation Models frameworkで画像分析
ryodeveloper
1
120
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
170
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
530
型も通る、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
380
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
260
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
470
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Crafting Experiences
bethany
1
230
Building AI with AI
inesmontani
PRO
1
1.1k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
350
Agile that works and the tools we love
rasmusluckow
331
22k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
640
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
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