#[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 objc2_foundation::NSObject
, you probably
want to use that path instead.
Implementations§
source§impl NSObject
impl NSObject
sourcepub fn init(this: Allocated<Self>) -> Retained<Self> ⓘ
pub fn init(this: Allocated<Self>) -> Retained<Self> ⓘ
Initialize an already allocated object.
See Apple’s documentation for details.
§Example
use objc2::runtime::NSObject;
use objc2::ClassType;
let obj = NSObject::init(NSObject::alloc());
sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
sourcepub unsafe fn get_ivar<T: Encode>(&self, name: &str) -> &T
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T: Encode>(&self, name: &str) -> &T
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
sourcepub unsafe fn get_mut_ivar<T: Encode>(&mut self, name: &str) -> &mut T
👎Deprecated: this is difficult to use correctly, use Ivar::load_mut
instead.
pub unsafe fn get_mut_ivar<T: Encode>(&mut self, name: &str) -> &mut T
Ivar::load_mut
instead.Use Ivar::load_mut
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
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 DefaultRetained for NSObject
impl DefaultRetained for NSObject
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§fn isEqual(&self, other: &AnyObject) -> bool
fn isEqual(&self, other: &AnyObject) -> bool
source§fn hash(&self) -> NSUInteger
fn hash(&self) -> NSUInteger
source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
source§fn is_kind_of<T: ClassType>(&self) -> bool
fn is_kind_of<T: ClassType>(&self) -> bool
source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
source§fn description(&self) -> Retained<NSObject> ⓘ
fn description(&self) -> Retained<NSObject> ⓘ
source§fn debugDescription(&self) -> Retained<NSObject> ⓘ
fn debugDescription(&self) -> Retained<NSObject> ⓘ
source§fn retainCount(&self) -> NSUInteger
fn retainCount(&self) -> NSUInteger
source§impl PartialEq for NSObject
impl PartialEq 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 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.
impl Message for NSObject
Auto Trait Implementations§
impl !Freeze for NSObject
impl !RefUnwindSafe for NSObject
impl !Send for NSObject
impl !Sync for NSObject
impl !Unpin for NSObject
impl !UnwindSafe for NSObject
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CounterpartOrSelf for T
impl<T> CounterpartOrSelf for T
§type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
Self
if the type has no
immutable counterpart. Read more§type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
Self
if the type has no
mutable counterpart. Read more