pub struct Model { /* private fields */ }Expand description
An observable model: a class instance, a registrar, and its named properties.
Cloning shares all three, as a class reference does in Swift — two handles to one model, not two models.
Implementations§
Source§impl Model
impl Model
Sourcepub fn as_object(&self) -> *mut c_void
pub fn as_object(&self) -> *mut c_void
The object itself, for handing to SwiftUI.
What .environment(_ object:) and focusedSceneValue(_ object:) take:
an AnyObject that conforms to Observable, which this is.
Sourcepub fn conformance(&self) -> (*const c_void, *const c_void)
pub fn conformance(&self) -> (*const c_void, *const c_void)
The model’s Swift metadata and its Observable conformance.
Sourcepub fn property<T: KeyValue>(
&self,
name: &str,
initial: impl IntoKeyValue<T>,
) -> Property<T>
pub fn property<T: KeyValue>( &self, name: &str, initial: impl IntoKeyValue<T>, ) -> Property<T>
A named property of this model, declared with initial if it is new.
Calling this twice with the same name returns two handles to one
property — the second initial is ignored, as a stored property’s
initialiser is after the object exists. That is what lets a view and the
code that updates it each ask for the property they mean without either
having to own it.
§Panics
If name was declared with a different type, here or on another model: a
property name is one key path, and a key path has one value type.
Sourcepub fn get(&self) -> i64
pub fn get(&self) -> i64
The default Int property — see Property::get.
Sourcepub fn set(&self, value: i64)
pub fn set(&self, value: i64)
The default Int property — see Property::set.
Sourcepub fn peek(&self) -> i64
pub fn peek(&self) -> i64
The default Int property — see Property::peek.