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.5k
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
1
770
waiwai-swiftpm-part2
d_date
2
390
わいわいSwift PM part 1
d_date
2
340
What's new in Firebase 2021
d_date
2
1.3k
CI/CDをミニマルに構築する
d_date
1
500
Swift Package centered project - Build and Practice
d_date
20
12k
How to write Great Proposal
d_date
4
910
Thinking about Architecture for SwiftUI
d_date
8
2.2k
Integrate your app to modern world in Niigata
d_date
0
590
Other Decks in Programming
See All in Programming
Androidで不安定なPlatform Viewsとの闘い
temoki
0
220
ライブラリをパブリッシュせずにすばやく試す
exoego
2
120
#kaigieffect LT 2024 - rexml-css_selector: A REXML extension for supporting CSS selector
makenowjust
1
230
Platform Engineering with Spring Boot
thombergs
0
390
Introduction to safe programming with numeric library / 数値ライブラリで始める安全なプログラミング
boykush
2
12k
型推論のちょっと深い話
omochi
0
290
LangGraphを用いたマルチエージェント
yuto2000
2
710
「ソフトウェア設計」のドメイン - 「データモデリングでドメインを駆動する」を読んで
hidenorigoto
7
2.2k
RustのReturn-position impl trait in trait (RPITIT) の実装を雑に見てみる
tako8ki
1
130
Deriving derived state: derivedStateOf explained (dcSF 24)
zachklipp
1
140
Dive into gomock / Go Conference 2024
utgwkk
12
2.9k
RubyKaigi参加歴をふりかえる / Looking Back on My RubyKaigi Participation History #kaigieffectLT
expajp
2
290
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
176
21k
Navigating Team Friction
lara
179
13k
How GitHub (no longer) Works
holman
305
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
660
120k
Principles of Awesome APIs and How to Build Them.
keavy
122
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
34
6.2k
A Tale of Four Properties
chriscoyier
153
22k
Creatively Recalculating Your Daily Design Routine
revolveconf
213
11k
Web development in the modern age
philhawksworth
203
10k
WebSockets: Embracing the real-time Web
robhawkes
59
7.1k
Product Roadmaps are Hard
iamctodd
46
9.9k
YesSQL, Process and Tooling at Scale
rocio
165
14k
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