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
2
980
waiwai-swiftpm-part2
d_date
3
430
わいわいSwift PM part 1
d_date
2
350
What's new in Firebase 2021
d_date
2
1.3k
CI/CDをミニマルに構築する
d_date
1
520
Swift Package centered project - Build and Practice
d_date
20
12k
How to write Great Proposal
d_date
4
1.1k
Thinking about Architecture for SwiftUI
d_date
8
2.2k
Integrate your app to modern world in Niigata
d_date
0
610
Other Decks in Programming
See All in Programming
Hono・Prisma・AWSでGeoなAPI開発
nokonoko1203
5
610
実践 Advanced CallKit 〜快適な通話の実現に向けて〜
mot_techtalk
3
110
暴走のウホーレン 〜想いってのはvimrcにしないと伝わらないんだぜ〜 / iosdc_japan_2024
uhooi
1
240
REXML改善のその後
naitoh
0
150
プログラマのための音楽入門
cheebow
4
540
Kotlin 2.0 and Beyond
antonarhipov
2
130
LangGraphでのHuman-in-the-Loopの実装
os1ma
3
630
The Future of Frontend i18n : Intl.MessageFormat
sajikix
1
2.4k
快適な開発と高セキュリティを実現するCryptoKitを活用したCoreDataのデータ暗号化術
grandbig
1
300
『ドメイン駆動設計をはじめよう』中核の業務領域
masuda220
PRO
5
850
労務ドメインを快適に開発する方法 / How to Comfortably Develop in the Labor Domain
yuki21
1
250
Scala におけるコンパイラエラーとの付き合い方
chencmd
1
160
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
165
48k
Designing Experiences People Love
moore
138
23k
Teambox: Starting and Learning
jrom
131
8.7k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
Optimizing for Happiness
mojombo
375
69k
The Cost Of JavaScript in 2023
addyosmani
39
5.1k
The Invisible Customer
myddelton
119
13k
Fireside Chat
paigeccino
31
2.9k
Automating Front-end Workflow
addyosmani
1365
200k
Producing Creativity
orderedlist
PRO
340
39k
The Pragmatic Product Professional
lauravandoore
30
6.2k
Raft: Consensus for Rubyists
vanstee
135
6.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