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.3k
waiwai-swiftpm-part2
d_date
3
470
わいわいSwift PM part 1
d_date
2
380
What's new in Firebase 2021
d_date
2
1.4k
CI/CDをミニマルに構築する
d_date
1
540
Swift Package centered project - Build and Practice
d_date
20
13k
How to write Great Proposal
d_date
4
1.2k
Thinking about Architecture for SwiftUI
d_date
8
2.3k
Integrate your app to modern world in Niigata
d_date
0
630
Other Decks in Programming
See All in Programming
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
260
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
630
Оптимизируем производительность блока Казначейство
lamodatech
0
870
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
860
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
330
快速入門可觀測性
blueswen
0
480
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
360
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
390
ドメインイベント増えすぎ問題
h0r15h0
2
540
선언형 UI에서의 상태관리
l2hyunwoo
0
250
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
410
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
390
Featured
See All Featured
Making Projects Easy
brettharned
116
6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Building an army of robots
kneath
302
44k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
How to Ace a Technical Interview
jacobian
276
23k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Designing Experiences People Love
moore
139
23k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
340
It's Worth the Effort
3n
183
28k
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