Skip to main content

set_state

Function set_state 

Source
pub fn set_state(id: i64, value: i64) -> bool
Expand description

Write a new value through the captured Binding, which is what makes SwiftUI invalidate and re-run the body.

Returns false if the body has not run yet, so there is nothing to write to.

Examples found in repository?
examples/ios_app.rs (line 78)
72fn refresh() {
73    use std::sync::atomic::Ordering;
74    static GENERATION: std::sync::atomic::AtomicI64 = std::sync::atomic::AtomicI64::new(0);
75    let id = ROOT_ID.load(Ordering::Acquire);
76    if id >= 0 {
77        let n = GENERATION.fetch_add(1, Ordering::Relaxed) + 1;
78        swiftui_native::state::set_state(id, n);
79    }
80}