pub struct Weak<T: ?Sized> { /* private fields */ }
Expand description
A weak pointer to an Objective-C reference counted object.
The object is allowed to be deallocated while the weak pointer is alive, though the backing allocation for the object can only be released once all weak pointers are gone.
Useful for breaking reference cycles and safely checking whether an object has been deallocated.
§Comparison to std
types
This is the Objective-C equivalent of sync::Weak
from the standard
library, and hence is only usable on types where Retained<T>
acts like
sync::Arc
, a.k.a. on non-mutable types.
Implementations§
source§impl<T: Message> Weak<T>
impl<T: Message> Weak<T>
sourcepub fn new(obj: &T) -> Selfwhere
T: IsRetainable,
pub fn new(obj: &T) -> Selfwhere
T: IsRetainable,
Construct a new weak pointer that references the given object.
sourcepub fn from_id(obj: &Retained<T>) -> Selfwhere
T: IsIdCloneable,
pub fn from_id(obj: &Retained<T>) -> Selfwhere
T: IsIdCloneable,
Construct a new weak pointer that references the given Retained
.
Soft-deprecated alias of Weak::from_retained
.
sourcepub fn from_retained(obj: &Retained<T>) -> Selfwhere
T: IsIdCloneable,
pub fn from_retained(obj: &Retained<T>) -> Selfwhere
T: IsIdCloneable,
Trait Implementations§
source§impl<T: Message + IsRetainable> Default for Weak<T>
impl<T: Message + IsRetainable> Default for Weak<T>
source§fn default() -> Self
fn default() -> Self
Constructs a new weak pointer that doesn’t reference any object.
Calling Self::load
on the return value always gives None
.