Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TCAの Shared Stateって どういう仕組みになってんの?

yimajo
March 18, 2024

TCAの Shared Stateって どういう仕組みになってんの?

【iOS】TCAでわいわいLT会
https://uzabase-tech.connpass.com/event/309323/

yimajo

March 18, 2024
Tweet

More Decks by yimajo

Other Decks in Programming

Transcript

  1. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  2. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  3. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  4. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  5. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  6. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  7. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> class ValueReference: Reference { var persistenceKey : (any PersistenceKey<Value>)? … } 0CTFSWBUJPO QFSDFQUJPO ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  8. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> class ValueReference: Reference { var persistenceKey : (any PersistenceKey<Value>)? … } 0CTFSWBUJPO QFSDFQUJPO ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB
  9. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> class ValueReference: Reference { var persistenceKey : (any PersistenceKey<Value>)? … } 0CTFSWBUJPO QFSDFQUJPO ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB struct InMemoryKey<Value>: PersistenceKey 1FSTJTUFODF,FZ४ڌࡾॐ࢜Λ࿈Ε͖ͯͨΑ struct AppStorageKey<Value>: PersistenceKey struct FileStorageKey<Value>: PersistenceKey
  10. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> class ValueReference: Reference { var persistenceKey : (any PersistenceKey<Value>)? … } 0CTFSWBUJPO QFSDFQUJPO ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB struct InMemoryKey<Value>: PersistenceKey 1FSTJTUFODF,FZ४ڌࡾॐ࢜Λ࿈Ε͖ͯͨΑ struct AppStorageKey<Value>: PersistenceKey struct FileStorageKey<Value>: PersistenceKey
  11. @ObservableState struct State { @Shared(.appStorage(“count”)) var count: Int } @ObservableState

    struct State { @Shared(.inMemory(“text")) var text: String ɹ @Shared(.appStorage(“count”)) var count: Int } "OZ)BTIBCMF 3FGFSFODF JO.FNPSZ lUFYUz BQQ4UPSFHF lDPVOUz ࢀরڞ༗ LockIsolated<[AnyHashable: any Reference]> class ValueReference: Reference { var persistenceKey : (any PersistenceKey<Value>)? … } 0CTFSWBUJPO QFSDFQUJPO ˏPropertyWrapper struct Shared<Value> { let reference: any Reference public init( _ persistenceKey: some PersistenceKey<Value>, … ) { … @Dependency( PersistentReferencesKey.self ) var references … } … 5IF$PNQPTBCMF"SDIJUFDUVSF TIBSFETUBUFCFUB struct InMemoryKey<Value>: PersistenceKey 1FSTJTUFODF,FZ४ڌࡾॐ࢜Λ࿈Ε͖ͯͨΑ struct AppStorageKey<Value>: PersistenceKey struct FileStorageKey<Value>: PersistenceKey protocol PersistenceKey<Value> { func load(…) -> Value? func save(_ value: Value) func subscribe( … ) }
  12. ࣗݾ঺հZJNBKP w גࣜձࣾΩϡϦΦγςΟιϑτ΢ΣΞ w 5$"ؔ࿈ w 5$"ͰͷJ04ΞϓϦ։ൃʹؔ͢ΔΞυόΠε΋࢓ࣄʹ͍ͯ͠·͢ w &$ͷΞϓϦ w

    ແਓड෇ͷ໊ࢗͷΞϓϦ w ݸਓ։ൃ5$"࢖ͬͨΞϓϦ w ৆ຯظݶಡΈऔΔΞϓϦ Έͳ͞Μ͕ڵຯ͋Γͦ͏ͳ࿩୊ ΞυόΠεͷΑ͋͘Δڞ௨఺΍ "OESPJEΞϓϦ͔͠࡞ͬͨ͜ͱ͕ͳ͍ਓ͕ &$αΠτͷΞϓϦͰ5$"Λ࢖͏࿩ɻ