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
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
初めてDefinitelyTypedにPRを出した話
syumai
0
400
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Outline View in SwiftUI
1024jp
1
330
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Featured
See All Featured
Speed Design
sergeychernyshev
24
610
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Music & Morning Musume
bryan
46
6.2k
Scaling GitHub
holman
458
140k
The World Runs on Bad Software
bkeepers
PRO
65
11k
GitHub's CSS Performance
jonrohan
1030
460k
For a Future-Friendly Web
brad_frost
175
9.4k
Faster Mobile Websites
deanohume
305
30k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Designing for Performance
lara
604
68k
Code Reviewing Like a Champion
maltzj
520
39k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
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