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
How to migrate to Swift 4
Search
d_date
June 27, 2017
Programming
0
1.6k
How to migrate to Swift 4
2017/06/27 Geek Garage iOS vol.3
d_date
June 27, 2017
Tweet
Share
More Decks by d_date
See All by d_date
TCA Practice in 5 min
d_date
2
1.5k
waiwai-swiftpm-part2
d_date
3
510
わいわいSwift PM part 1
d_date
2
410
What's new in Firebase 2021
d_date
2
1.5k
CI/CDをミニマルに構築する
d_date
1
570
Swift Package centered project - Build and Practice
d_date
20
14k
How to write Great Proposal
d_date
4
1.6k
Thinking about Architecture for SwiftUI
d_date
8
2.4k
Integrate your app to modern world in Niigata
d_date
0
670
Other Decks in Programming
See All in Programming
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
120
CursorはMCPを使った方が良いぞ
taigakono
1
170
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
190
Haskell でアルゴリズムを抽象化する / 関数型言語で競技プログラミング
naoya
17
4.9k
エラーって何種類あるの?
kajitack
5
300
Benchmark
sysong
0
260
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
230
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
800
XSLTで作るBrainfuck処理系
makki_d
0
210
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
930
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
250
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
Featured
See All Featured
Done Done
chrislema
184
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Code Review Best Practice
trishagee
68
18k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
What's in a price? How to price your products and services
michaelherold
246
12k
Transcript
How to migrate to Swift 4 Daiki Matsudate,@d_date, iOS Freelancer
Distribution GeekGarage
Daiki Matsudate,@d_date • iOS Freelancer • Supporting Realm as News
Translator • Organizer of CLEM (announce later) • WWDC17 Attendee
Daiki Matsudate,@d_date • iOS Freelancer • Supporting Realm as News
Translator • Organizer of CLEM (announce later) • WWDC17 Attendee
Agenda • How to migrate to Swift 4 using Xcode
9 Beta • [SE-0160] Limited @objc inference • [SE-0110] Distinguish between single-tuple and multiple-argument function types • Renamed some constants • Decodable
[SE-0160] Limited @objc inference • https://github.com/apple/swift-evolution/blob/master/ proposals/0160-objc-inference.md
@objc in Swift 3.x • Objective-CͰݺͼग़ͤΔͷʹ͍ͭͯɺSwiftଆͰ໌ࣔత ʹએݴͰ͖Δ • Θ͟Θ͟@objcΛॻ͔ͳ͍͍ͯ͘Α͏ʹ ਪͯ͘͠
ΕΔ
@objc in Swift 3.x ͷ • Objective-CͰݺͼग़ͤΔͷʹ͍ͭͯɺSwiftଆͰ໌ࣔత ʹએݴͰ͖Δ • Θ͟Θ͟@objcΛॻ͔ͳ͍͍ͯ͘Α͏ʹ
ਪͯ͘͠ ΕΔ → աͰʁʁ
• SwiftͷΫϥεObjective-CͷSelectorͷিಥΛҾ ͖ى͕ͪ͜͠ @objc in Swift 3.x ͷ
• Swift API Design GuidelineʹԊͬͯॻ͍ͯɺ Objective-CͰݺͼग़͢ͱ͖ʹObjective-C Coding Guidelineʹ͢Δ໊લʹม͞Ε͕ͪɻ ಛʹɺinitializerɺͦͷ໊લʹୈҰҾΛؚΊͳ ͍͚ͯ͘ͳ͍ͷͰɺ@objcඞ͚ͣͭΔ͜ͱʹ
ͳΔɻ @objc in Swift 3.x ͷ
• SwiftίϯύΠϥObjective-C Calling Convention ͔ΒSwift Calling Conventionม͢Δ"thunk"ϝ ιουΛ࡞ΔͨΊɺόΠφϦαΠζ͕૿େ͢Δɻ @objc in
Swift 3.x ͷ
@objc in future
@objc in future Objective-CͰඞཁͳͱ͜Ζ͚ͩʹ @objcΛ͚ͭΔΑ͏ʹਪΛݮΒ͢ ʲํʳ
Ҿ͖ଓ͖@objcΛਪ͢Δͷ 1.@objcͷ͍͍ͭͯΔએݴͷΦʔόʔϥΠυͷͱ͖
Ҿ͖ଓ͖@objcΛਪ͢Δͷ 2. @objcͷ͍ͭͨϓϩτίϧͷཁ݅Λຬͨ͢ͱ͖
Ҿ͖ଓ͖@objcΛਪ͢Δͷ 3. @IBOutlet,@IBActionଐੑ͕͍͍ͭͯΔͱ͖ 4. @NSManagedଐੑ͕͍͍ͭͯΔͱ͖ Interface BuilderͱͷΠϯλϥΫγϣϯ͕ Objective-CϥϯλΠϜͰߦΘΕΔͨΊ Core DataͱͷΠϯλϥΫγϣϯ͕
Objective-CϥϯλΠϜͰߦΘΕΔͨΊ
ՃͰ@objcΛਪ͢Δͷ 1. @GKInspectableଐੑ͕͍͍ͭͯΔͱ͖ 2. @IBInspectableଐੑ͕͍͍ͭͯΔͱ͖ GameplayKitͱͷΠϯλϥΫγϣϯ͕ Objective-CϥϯλΠϜͰߦΘΕΔͨΊ Interface BuilderͱͷΠϯλϥΫγϣϯ͕ Objective-CϥϯλΠϜͰߦΘΕΔͨΊ
@objcΛਪ͠ͳ͘ͳΔͷ 1. dynamic
@objcΛਪ͠ͳ͘ͳΔͷ 2. NSObject༝དྷͷΫϥε NSObjectΛܧঝ͍ͯ͠ΔΫϥεͰ͋ͬͯɺ @objcͳ͠ͰObjective-C͔Βݺͼग़ͤͳ͍ɻ
@objcΛਪ͠ͳ͘ͳΔͷ 2. NSObject༝དྷͷΫϥε extensionͰɺ@objcͳ͠ͰObjective-C͔Βݺͼ ग़ͤͳ͍ɻ
@objcMembersͷಋೖ Ϋϥεશମ͕@objcͰ͋Δ͜ͱ͕ٻΊΒΕΔࡍɺ @objcMembersΛ͚ͭΔ
@objcMembersͷಋೖ @objcMembersΛ͚ͭΔΫϥεɺObjecive-Cଆ Ͱ swift_objc_membersΛ͚ͭΔ
Extensionʹ͓͚Δ@objcͷON/OFF @nonobjcΛextensionʹ͚ͭΔ͜ͱͰɺ@objcͷ ର֎ͱ͢Δ͜ͱ͕Ͱ͖Δɻ
Swift 4Ҡߦͷͱ͖ Ͳ͏͢Ε͍͍ͷ…ʁ
"Minimal" migration workflow!
Minimal migration workflow • Step 1: Swift 4ϞʔυͰɺ@objcਪ͞ΕͨՕॴͷͯ͢ͷܯࠂΛղ ফ͢Δɻ
Minimal migration workflow • Step 2: SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINTΛ1ʙ3ͷؒ ͷʹઃఆ͠ɺΞϓϦΛςετɻ 1.ΤϯτϦϙΠϯτͷݺग़ΛϝοηʔδͰه 2.ϩάΛͱΓɺόοΫτϨʔεΛൃߦ
3.όοΫτϨʔεͰه͠ɺΫϥογϡ͠·͢ɻ
Minimal migration workflow • Step 3: ͜ͷ࣌ͰɺSwift 4ʹҠߦՄೳɻSwift 4ΛϏϧυ͢Δͱɺ ഇࢭ༧ఆͷϧʔϧʹج͍ͮͯ@objc͕ਪଌ͞ΕͨΓͷέʔ
εͷObjective-CΤϯτϦϙΠϯτ͕আ͞ΕΔɻ
Summary in @objc • dynamic, NSObject༝དྷͷΫϥεͰ@objcਪ͕͞Ε ͳ͘ͳΔ • @objcMembersʹΑΓclassશମʹ@objcΛదԠͰ͖ΔΑ ͏ʹͳΔ
• @nonobjcΛextensionʹదԠ͢Δ͜ͱͰͦͷextension @objcͷదԠ֎ͱ͢Δ͜ͱ͕Ͱ͖Δ
[SE-0110] Distinguish between single- tuple and multiple-argument function types
[SE-0110] Distinguish between single-tuple and multiple-argument function types •Swift 3.1
• Swift 4Ͱมߋ
Renamed some constants
NSAttributedStringKey • Renamed to enum • NSFontAttributedName -> NSAttributedStringKey.font •
NSParagraphStyleAttributeName -> NSAttributedStringKey.paragraphStyle
NSAttributedStringKey let mStr = NSMutableAttributedString() mStr.addAttribute(.foregroundColor, value: UIColor.white, range: NSRange())
mStr.addAttributes([.font : UIFont()], range: NSRange())
NSAttributedStringKey let mStr = NSMutableAttributedString() mStr.addAttribute(.foregroundColor, value: UIColor.white, range: NSRange())
mStr.addAttributes([.font : UIFont()], range: NSRange()) "
NSAttributedStringKey let item = UIBarButtonItem() let attr = [NSAttributedStringKey.foregroundColor.rawValue :
UIColor.white] item.setTitleTextAttributes(attr, for: .normal)
NSAttributedStringKey let item = UIBarButtonItem() let attr = [NSAttributedStringKey.foregroundColor.rawValue :
UIColor.white] item.setTitleTextAttributes(attr, for: .normal) #
Structures in AVFoundation • AVLayerVideoGravityResizeAspectFill -> AVLayerVideoGravity.resizeAspectFill
Decodable • [SE-0166] Swift Archival & Serialization
[SE-0166] Swift Archival & Serialization • Codable (Encodable & Decodableͷtypealias)ͷಋೖ
[SE-0166] Swift Archival & Serialization • Codable (Encodable & Decodableͷtypealias)ͷಋೖ
Himotoki
Himotoki
Decodable
Decodable -> Himotoki.Decodable
None
None
GEEK GARAGE