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
440
K/NとNSKeyedArchiverと私
RyuNen344
March 16, 2023
Tweet
Share
More Decks by RyuNen344
See All by RyuNen344
サプライチェーン攻撃に備える
ryunen344
0
1.4k
Okioに愛を込めて
ryunen344
3
1.7k
Firebase Hostingを使ってPasskeyをandroidアプリで試してみよう
ryunen344
2
1.4k
Xcode Meets Gradle
ryunen344
0
300
わかった気になる、Coroutine1.7.0のチャンネルのパフォーマンス向上
ryunen344
0
330
ComposeのModalBottomSheetは (まだ)沼
ryunen344
1
1.5k
うわっ…もしかして私のコー ド、遅すぎ…?
ryunen344
1
800
K/NでCryptoKit使いたかった
ryunen344
0
360
SwiftPM with KMMをprivateなGitHub Releaseで運用する
ryunen344
0
320
Other Decks in Programming
See All in Programming
Remix on Hono on Cloudflare Workers
yusukebe
1
290
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
初めてDefinitelyTypedにPRを出した話
syumai
0
410
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
110
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
イベント駆動で成長して委員会
happymana
1
320
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
290
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
65
4.4k
Side Projects
sachag
452
42k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
93
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
What's new in Ruby 2.0
geeforr
343
31k
What's in a price? How to price your products and services
michaelherold
243
12k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
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