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
K/NとNSKeyedArchiverと私
Search
RyuNen344
March 16, 2023
Programming
0
450
K/NとNSKeyedArchiverと私
RyuNen344
March 16, 2023
Tweet
Share
More Decks by RyuNen344
See All by RyuNen344
サプライチェーン攻撃に備える
ryunen344
0
1.6k
Okioに愛を込めて
ryunen344
3
1.8k
Firebase Hostingを使ってPasskeyをandroidアプリで試してみよう
ryunen344
2
1.5k
Xcode Meets Gradle
ryunen344
0
310
わかった気になる、Coroutine1.7.0のチャンネルのパフォーマンス向上
ryunen344
0
330
ComposeのModalBottomSheetは (まだ)沼
ryunen344
1
1.6k
うわっ…もしかして私のコー ド、遅すぎ…?
ryunen344
1
810
K/NでCryptoKit使いたかった
ryunen344
0
380
SwiftPM with KMMをprivateなGitHub Releaseで運用する
ryunen344
0
340
Other Decks in Programming
See All in Programming
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
720
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
310
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
120
快速入門可觀測性
blueswen
0
340
Beyond ORM
77web
3
430
たのしいparse.y
ydah
3
120
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
What's in a price? How to price your products and services
michaelherold
243
12k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Building an army of robots
kneath
302
44k
Adopting Sorbet at Scale
ufuk
73
9.1k
A better future with KSS
kneath
238
17k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Transcript
K/NͱNSKeyedArchiverͱࢲ 2023.03.16 CA.aab #2 RyuNen344/Bunjiro Miyoshi
iOSͷ͔ͬΓͰ ͝ΊΜͳ͍͞🙇 ͡Ίʹ
ຊͷΰʔϧ • Obj-CͷAPIΛK/NͰͪΌΜͱ͑Δͱ͍͏͜ͱΛͬͯΒ͏(ͦ ͦ͑Δ͜ͱᨳΘΕ͍ͯΔ͕) • K/NͰ࣮Ͱ͖Δ͜ͱΛΔ͜ͱͰKMMಋೖ࣌ͷϋʔυϧࢥͬͨΑ Γߴ͘ͳ͍͜ͱΛͬͯΒ͏ • androidΤϯδχΞ͕Obj-CͷK/NΛॻ͘ࡍʹԿΛϦϑΝϨϯεʹ͢Ε ͍͍ͷ͔ΛͬͯΒ͏
ϞόΠϧք۾ͰKMMಋೖ͕ͬͱਐΉʂ͏Ε͍͠ʂ
ొਓ • K/N • NSKeyedArchiver • ࢲ
ొਓɿK/N • Kotlin Nativeͷ͜ͱ • KotlinͰॻ͍ͨίʔυΛ֤ϓϥοτϑΥʔϜͰ࣮ߦՄೳͳωΠςΟϒ όΠφϦʹม࣮ͯ͠ߦͰ͖ΔΈ • ͍ΖΜͳϓϥοτϑΥʔϜʹରԠ͍ͯ͠Δ •
KMMͷiOSଆ͜Ε͕ಈ͍͍ͯΔ
ొਓɿNSKeyedArchiver • Foundation.frameworkͷΫϥε • JavaͰ͍͏ͱ͜ΖͷserializableͳͷΛserialize, deserialize͢ΔΫϥ ε • Obj-C࣌ͰΑ͘ར༻͞Ε͍ͯͨ(Β͍͠ɺJsonपΓͷ࣮͕͍Βͳ͍ ͔Β)
• RyuNen344/Bunjiro Miyoshi • teamLab.Incॴଐ • ݏ͍ͳExceptionInvalidMutabilityException • ͖ͳExceptionIllegalStateException ొਓɿࢲ
ຊͷରԠද J04 BOESPJE ͭ·Γʁ 6TFS%FGBVMUT 4IBSFE1SFGFSFODFT YNM /4$PEJOH !4FSJBMJ[BCMF TFSJBMJ[FՄೳϚʔΧʔ
/4,FZFE"SDIJWFS 0CKFDU0VUQVU4USFBN TFSJBMJ[F࣮ߦΫϥε /4,FZFE6OBSDIJWFS 0CKFDU*OQVU4USFBN EFTFSJBMJ[F࣮ߦΫϥε
Ұ࣌తͳใอଘઌ • DBʹอଘ͢Δ·Ͱແ͍σʔλ • android • SharedPreferencesʹॻ͖ग़͢ • ߏମJsonStringͱͯ͠ॻ͖ࠐΉ(͜ͱ͕ࢲଟ͍Ͱ͢, GsonͱMoshi͞·͞·)
• iOS • UserDefaultsʹॻ͖ग़͢ • NSData, NSString, NSNumber, NSDate, NSArray, NSDictionaryͷ੍ݶ͋Γ • ߏମNSDataͱͯ͠ॻ͖ࠐΉͷָ͕
ߏମͷSerialize#kotlin
ߏମͷSerialize#kotlin java.io.SerializableΛimplments͢Δ implement͢Δ͚ͩͰ fi eldΛserializeͯ͘͠ΕΔ
ߏମͷSerialize#kotlin ObjectOutputStream#writeObjectΛ࣮ߦ͢Δ
ߏମͷSerialize#Swift(Obj-C)
ߏମͷSerialize#Swift(Obj-C) Swift to Obj-C૬ޓӡ༻ͷͨΊʹNSObjectΛܧঝ ΤϯίʔυՄೳʹ͢ΔͨΊʹNSCodingʹ४ڌ
ߏମͷSerialize#Swift(Obj-C) encode, decode࣌ͷ࣮ڍಈΛ࣮
ߏମͷSerialize#Swift(Obj-C)
ߏମͷSerialize#Swift(Obj-C) Ͳ͏͍͏Classͷߏͳͷ͔(Metaใ)Λ NSKeyedˎˎʹڭ͑ࠐΉ
ߏମͷSerialize#Swift(Obj-C) unarchive͢Δͱ͖ʹରͷΫϥε͕͍ͬͯΔ มͷܕใͯ͋͛͠Δ
ߏମͷSerialize#Swift(Obj-C) to K/N ❓. NSData(Data)͕K/NͩͱԿ͔ΛΔ ❓. NSCoding protocolʹ४ڌͨ͠classΛ࡞Γํ ❓. NSKeyed**ʹڭ͑ࠐΉΫϥεͷࢦఆͷํ
NSData(Data)#K/N • Kotlin.StringͱObj-C.NSStringK/NଆͰޓ͕୲อ͞Ε͍ͯΔ • NSString#dataUsingEncoding(encoding)Λ༻ͯ͠ม͢Δ
Class implements NSCoding#K/N • Obj-C.@protocolKotlin.interfaceʹޓ
Class implements NSCoding#K/N • Obj-C.@protocolKotlin.interfaceʹޓ Unresolved Reference😂
Class implements NSCoding#K/N Μʁ🤔
Class implements NSCoding#K/N
Class implements NSCoding#K/N Obj-Cͷprotocol໊ͱඍົʹҧ͏ͷͰҙ͢Δ protocolΛ࣮͢ΔࡍNSObjectΛܧঝ͢Δ(͠ͳ ͍ͱϏϧυ௨Βͳ͍ʣ
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N • ͦͦNSKeyed**ʹڭ͑ࠐΉΫϥεͱͳΜͳͷ͔Λ͠Γ͍ͨ A. →ެࣜΛࢀর͢Δ • https://developer.apple.com/documentation/foundation/ nskeyedarchiver • https://developer.apple.com/documentation/foundation/
nskeyedunarchiver
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N android developer͕kotlinͱjavaΛΓସ͑ΒΕΔΑ͏ʹ swiftͱObj-CΛΓସ͑ΒΕΔ K/NObj-CޓͳͷͰObj-CͷDocΛݟΔඞཁ͕͋Δ
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N AnyClass(swift)͡Όͳͯ͘Class(Obj-C)Λ͢ඞཁ͕͋Δ
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N • swiftͱkotlinࣅ͍ͯΔ(ݸਓͷײ)ͷͰswiftΛࢀߟʹίʔυΛॻ͘ ·ͨUnresolved Reference😂
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N • Apple DeveloperʹNSObjectʹੜ͍͑ͯΔϝιουͱ͋Δ͕ Book.classForKeyedUnarchiver()Ͱݟ͔ͭΒͳ͍ɾɾɾɾɾɾ • Book.classForKeyedUnarchiver()Ͱݺͼग़ͤΔΑ͏ʹ͍͔ͨ͠Βɺ companion objectΛͳʹ͔͢Δඞཁ͕͋Γͦ͏ɾɾɾɾɾɾ
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N Μʁ🤔
NSKeyed**ʹKotlinΛΘ͔ΒͤΔ#K/N ݺΔΑ͏ʹͳͬͨ😃 ͋ͱUnarchive͢Δ͚ͩ
·ͱΊ • protocolK/N্ͩͱ**Protocolͱ͍͏interfaceʹͳͬͯͨΓ͢Δ • Type MethodK/N্ͩͱ**Meta classʹੜ͍͑ͯͨΓ͢Δ • SwiftͱObj-CͰAPI͕ҧ͏ͷͰެࣜDocObj-CͷΛࢀর͢Δ •
Obj-CͷAPI͕K/N্ͩͱͲͷΑ͏ͳఆٛʹͳ͍ͬͯΔ͔IDE্Ͱδϟϯϓͯ֬͠ ೝͰ͖ΔɺJetBrainsΛ৴͡Ζʂʂ • archive, unarchive͢ΔίʔυࢀরͷϦϙδτϦʹࡌͤͯΔͷͰͦ͜ͰΈͯͩ͘ ͍͞
͜ΕͰKMM͕ḿΓ·͢Ͷ😉
ࢀߟࢿྉ • RyuNen344/KNKeyedArchiver • https://github.com/RyuNen344/KNKeyedArchiver • native-objc-interop • https://kotlinlang.org/docs/native-objc-interop.html#mappings •
NSObject • https://developer.apple.com/documentation/objectivec/nsobject? language=objc