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
350
SwiftPM with KMMをprivateなGitHub Releaseで運用する
ryunen344
0
320
Other Decks in Programming
See All in Programming
Click-free releases & the making of a CLI app
oheyadam
2
100
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
53
34k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
390
C++でシェーダを書く
fadis
6
3.9k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
440
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
200
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
4
1.5k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
4
2k
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
420
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
540
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
170
Identifying User Idenity
moro
6
9.5k
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Adopting Sorbet at Scale
ufuk
73
9.1k
Designing the Hi-DPI Web
ddemaree
280
34k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Typedesign – Prime Four
hannesfritz
40
2.4k
Done Done
chrislema
181
16k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Documentation Writing (for coders)
carmenintech
65
4.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
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