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
370
SwiftPM with KMMをprivateなGitHub Releaseで運用する
ryunen344
0
340
Other Decks in Programming
See All in Programming
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
ドメインイベント増えすぎ問題
h0r15h0
1
230
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
Haze - Real time background blurring
chrisbanes
1
510
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
MCP with Cloudflare Workers
yusukebe
2
220
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
110
Recoilを剥がしている話
kirik
5
6.6k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
GitHub's CSS Performance
jonrohan
1030
460k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
It's Worth the Effort
3n
183
28k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
A Philosophy of Restraint
colly
203
16k
BBQ
matthewcrist
85
9.4k
Facilitating Awesome Meetings
lara
50
6.1k
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