pub struct StoredView<T: StoredValue> {
pub metadata: *const c_void,
pub witness_table: *const c_void,
pub id: i64,
/* private fields */
}Expand description
A runtime-built Swift view type with a real @AppStorage.
struct RustStored: View {
@AppStorage("key") var flag: T
var id: Int
var body: some View { <built by a Rust closure> }
}SwiftUI installs the property itself, by walking the reflection field
records — the same route @State takes in StatefulView. The body reads
the value through the wrapper, which is what records the dependency, so a
later set both persists to UserDefaults and re-runs the
body.
T is one of StoredValue: bool, i64, f64 or String.
Compare crate::views::BoundState::persistent, which reaches the same
store without SwiftUI’s involvement — the right tool when the state is
Rust’s rather than a view’s.
Fields§
§metadata: *const c_void§witness_table: *const c_void§id: i64Implementations§
Source§impl<T: StoredValue> StoredView<T>
impl<T: StoredValue> StoredView<T>
Sourcepub fn new(
key: &str,
default: T,
builder: impl Fn(T) -> ViewHandle + Send + 'static,
) -> Self
pub fn new( key: &str, default: T, builder: impl Fn(T) -> ViewHandle + Send + 'static, ) -> Self
Build the type and one instance, backed by key in UserDefaults.
Sourcepub fn binding(&self) -> Vec<u8> ⓘ
pub fn binding(&self) -> Vec<u8> ⓘ
The Binding<T> that Swift spells $flag.
Hand this to a control and the control is the stored value: changing
it writes through UserDefaults and re-runs the body, with no Rust
state in between. See crate::views::toggle_app_storage and
crate::views::slider_app_storage.
Sourcepub fn as_view(&self) -> ViewHandle
pub fn as_view(&self) -> ViewHandle
Wrap the instance so it can be hosted like any other view.