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
500
わいわいSwift PM part 1
d_date
2
400
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.3k
Thinking about Architecture for SwiftUI
d_date
8
2.4k
Integrate your app to modern world in Niigata
d_date
0
660
Other Decks in Programming
See All in Programming
Boast Code Party / RubyKaigi 2025 After Event
lemonade_37
0
110
Bedrock × Confluenceで簡単(?)社内RAG
iharuoru
1
130
REALITY コマンド作成チュートリアル
nishiuriraku
0
120
“技術カンファレンスで何か変わる?” ──RubyKaigi後の自分とチームを振り返る
ssagara00
0
120
Embracing Ruby magic
vinistock
2
260
JAWS DAYS 2025 re_Cheers: WEB
komakichi
0
120
note の Elasticsearch 更新系を支える技術
tchov
9
3.6k
Browser and UI #2 HTML/ARIA
ken7253
2
180
In geheimer Mission: AI Agents entwickeln
joergneumann
0
120
MySQL初心者が311個のカラムにNot NULL制約を追加していってALTER TABLEについて学んだ話
hatsu38
2
140
Road to Ruby for A Linguistics Nerd
hayat01sh1da
PRO
0
320
GitHub Copilot for Azureを使い倒したい
ymd65536
1
330
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
It's Worth the Effort
3n
184
28k
The Cost Of JavaScript in 2023
addyosmani
49
7.8k
For a Future-Friendly Web
brad_frost
177
9.7k
Six Lessons from altMBA
skipperchong
28
3.8k
The Invisible Side of Design
smashingmag
299
50k
Music & Morning Musume
bryan
47
6.5k
How to Ace a Technical Interview
jacobian
276
23k
Documentation Writing (for coders)
carmenintech
71
4.8k
How STYLIGHT went responsive
nonsquared
100
5.5k
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