Skip to content

Instantly share code, notes, and snippets.

@helje5
Created July 2, 2024 21:43
Show Gist options
  • Save helje5/6489a333fbec38a595adae270f4b2e56 to your computer and use it in GitHub Desktop.
Save helje5/6489a333fbec38a595adae270f4b2e56 to your computer and use it in GitHub Desktop.
What a Binding produced by Bindable looks like
▿ SwiftUI.Binding<Swift.Bool>
▿ transaction: SwiftUI.Transaction
▿ plist: []
- elements: nil
▿ location: SwiftUI.LocationBox<SwiftUI.Binding<Swift.Bool>.(unknown context at $1c460b9d4).ScopedLocation> #0
- super: SwiftUI.AnyLocation<Swift.Bool>
- super: SwiftUI.AnyLocationBase
▿ location: SwiftUI.Binding<Swift.Bool>.(unknown context at $1c460b9d4).ScopedLocation
▿ base: SwiftUI.LocationBox<SwiftUI.(unknown context at $1c3c342f4).ObjectLocation<TestGroup.Option, Swift.Bool>> #1
- super: SwiftUI.AnyLocation<Swift.Bool>
- super: SwiftUI.AnyLocationBase
▿ location: SwiftUI.(unknown context at $1c3c342f4).ObjectLocation<TestGroup.Option, Swift.Bool>
▿ base: TestGroup.Option #2
- title: "A"
- _selected: false
▿ _$observationRegistrar: Observation.ObservationRegistrar
▿ extent: Observation.ObservationRegistrar.(unknown context at $2251b3224).Extent #3
▿ context: Observation.ObservationRegistrar.Context
▿ state: Observation._ManagedCriticalState<Observation.ObservationRegistrar.(unknown context at $2251b32f4).State>
- buffer: Observation._ManagedCriticalState<Observation.ObservationRegistrar.(unknown context at $2251b32f4).State>.(unknown context at $2251b3140).LockedBuffer #4
▿ super: Swift.ManagedBuffer<Observation.ObservationRegistrar.(unknown context at $2251b32f4).State, Swift.UnsafeRawPointer>
▿ header: Observation.ObservationRegistrar.(unknown context at $2251b32f4).State
- id: 2
▿ observations: 2 key/value pairs
▿ (2 elements)
- key: 1
▿ value: Observation.ObservationRegistrar.(unknown context at $2251b32f4).State.Observation
▿ kind: Observation.ObservationRegistrar.(unknown context at $2251b32f4).State.ObservationKind.willSetTracking
- willSetTracking: (Function)
▿ properties: 1 member
- \Option.selected #5
- super: Swift.WritableKeyPath<TestGroup.Option, Swift.Bool>
- super: Swift.KeyPath<TestGroup.Option, Swift.Bool>
- super: Swift.PartialKeyPath<TestGroup.Option>
▿ super: Swift.AnyKeyPath
- _kvcKeyPathStringPtr: nil
▿ (2 elements)
- key: 0
▿ value: Observation.ObservationRegistrar.(unknown context at $2251b32f4).State.Observation
▿ kind: Observation.ObservationRegistrar.(unknown context at $2251b32f4).State.ObservationKind.willSetTracking
- willSetTracking: (Function)
▿ properties: 1 member
- \Option.selected #5
▿ lookups: 1 key/value pair
▿ (2 elements)
- key: \Option.selected #5
▿ value: 2 members
- 0
- 1
- keyPath: \Option.selected #5
- isolation: nil
▿ _cache: SwiftUI.AtomicBox<SwiftUI.LocationProjectionCache>
- buffer: SwiftUI.(unknown context at $1c461a7a8).AtomicBuffer<SwiftUI.LocationProjectionCache> #6
▿ super: Swift.ManagedBuffer<__C.os_unfair_lock_s, SwiftUI.LocationProjectionCache>
▿ header: __C.os_unfair_lock_s
- _os_unfair_lock_opaque: 0
- wasRead: true
▿ _cache: SwiftUI.AtomicBox<SwiftUI.LocationProjectionCache>
- buffer: SwiftUI.(unknown context at $1c461a7a8).AtomicBuffer<SwiftUI.LocationProjectionCache> #7
▿ super: Swift.ManagedBuffer<__C.os_unfair_lock_s, SwiftUI.LocationProjectionCache>
▿ header: __C.os_unfair_lock_s
- _os_unfair_lock_opaque: 0
- _value: false
@helje5
Copy link
Author

helje5 commented Jul 2, 2024

Things to note, a Binding has:

  • a transaction
  • the (I think last, right before DynamicElement.update()) _value
  • a backing storage, which can be a set of things, here we see:
    • something that seems to be specific to Observation
    • there is also a backing which is the usual setter/getter closures
    • and there are others for State and ObservableObject I think (though those might be abstracted out using AnyLocation, a layer below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment