#[repr(C)]pub struct NSObject { /* private fields */ }Expand description
The root class of most Objective-C class hierarchies.
This represents the NSObject class. The name “NSObject” also
refers to a protocol, see NSObjectProtocol for that.
Since this class is only available with the Foundation framework,
objc2 links to it for you.
This is exported under icrate::Foundation::NSObject, you probably
want to use that path instead.
Implementations§
Methods from Deref<Target = AnyObject>§
sourcepub unsafe fn ivar_ptr<T: Encode>(&self, name: &str) -> *mut T
pub unsafe fn ivar_ptr<T: Encode>(&self, name: &str) -> *mut T
Returns a pointer to the instance variable / ivar with the given name.
This is similar to UnsafeCell::get, see that for more information
on what is and isn’t safe to do.
Usually you will have defined the instance variable yourself with
ClassBuilder::add_ivar, the type of the ivar T must match the
type used in that.
Attempting to access or modify private implementation details of a class that you do no control using this is not supported, and may invoke undefined behaviour.
Library implementors are strongly encouraged to expose a safe interface to the ivar.
Panics
May panic if the object has no ivar with the given name. May also
panic if the type encoding of the ivar differs from the type encoding
of T.
This should purely seen as help while debugging and is not guaranteed
(e.g. it may be disabled when debug_assertions are off).
Safety
The object must have an instance variable with the given name, and it
must be of type T. Any invariants that the object have assumed about
the value of the instance variable must not be violated.
No thread syncronization is done on accesses to the variable, so you must ensure that any access to the returned pointer do not cause data races, and that Rust’s mutability rules are not otherwise violated.
sourcepub unsafe fn ivar<T: Encode>(&self, name: &str) -> &T
pub unsafe fn ivar<T: Encode>(&self, name: &str) -> &T
Returns a reference to the instance variable with the given name.
See AnyObject::ivar_ptr for more information, including on when
this panics.
Safety
The object must have an instance variable with the given name, and it
must be of type T.
No thread syncronization is done, so you must ensure that no other
thread is concurrently mutating the variable. This requirement can be
considered upheld if all mutation happens through
AnyObject::ivar_mut (since that takes &mut self).
sourcepub unsafe fn get_ivar<T: Encode>(&self, name: &str) -> &T
👎Deprecated: Use AnyObject::ivar instead.
pub unsafe fn get_ivar<T: Encode>(&self, name: &str) -> &T
AnyObject::ivar instead.sourcepub unsafe fn ivar_mut<T: Encode>(&mut self, name: &str) -> &mut T
pub unsafe fn ivar_mut<T: Encode>(&mut self, name: &str) -> &mut T
Returns a mutable reference to the ivar with the given name.
See AnyObject::ivar_ptr for more information, including on when
this panics.
Safety
The object must have an instance variable with the given name, and it
must be of type T.
This access happens through &mut self, which means we know it to be
the only reference, hence you do not need to do any work to ensure
that data races do not happen.
sourcepub unsafe fn get_mut_ivar<T: Encode>(&mut self, name: &str) -> &mut T
👎Deprecated: Use AnyObject::ivar_mut instead.
pub unsafe fn get_mut_ivar<T: Encode>(&mut self, name: &str) -> &mut T
AnyObject::ivar_mut instead.sourcepub unsafe fn set_ivar<T: Encode>(&mut self, name: &str, value: T)
pub unsafe fn set_ivar<T: Encode>(&mut self, name: &str, value: T)
Sets the value of the ivar with the given name.
This is a shorthand for AnyObject::ivar_mut, see that for more
information.
Safety
Same as AnyObject::ivar_mut.
Trait Implementations§
source§impl BorrowMut<AnyObject> for NSObject
impl BorrowMut<AnyObject> for NSObject
source§fn borrow_mut(&mut self) -> &mut AnyObject
fn borrow_mut(&mut self) -> &mut AnyObject
source§impl ClassType for NSObject
impl ClassType for NSObject
§type Mutability = Root
type Mutability = Root
source§const NAME: &'static str = "NSObject"
const NAME: &'static str = "NSObject"
source§fn class() -> &'static AnyClass
fn class() -> &'static AnyClass
source§fn as_super_mut(&mut self) -> &mut Self::Super
fn as_super_mut(&mut self) -> &mut Self::Super
source§impl Hash for NSObject
impl Hash for NSObject
Hashing in Objective-C has the exact same requirement as in Rust:
If two objects are equal (as determined by the isEqual: method), they must have the same hash value.
See https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418859-hash
source§impl NSObjectProtocol for NSObject
impl NSObjectProtocol for NSObject
source§impl PartialEq<NSObject> for NSObject
impl PartialEq<NSObject> for NSObject
Objective-C equality has approximately the same semantics as Rust equality (although less aptly specified).
At the very least, equality is expected to be symmetric and transitive, and that’s about the best we can do.
See also https://nshipster.com/equality/
source§impl ProtocolType for NSObject
impl ProtocolType for NSObject
source§impl RefEncode for NSObject
impl RefEncode for NSObject
source§const ENCODING_REF: Encoding = <AnyObject as crate::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <AnyObject as crate::RefEncode>::ENCODING_REF
impl Eq for NSObject
Most types’ equality is reflexive.