Struct objc2::runtime::AnyClass

source ·
#[repr(C)]
pub struct AnyClass(_);
Expand description

A type that represents an Objective-C class.

This is an opaque type meant to be used behind a shared reference &AnyClass, which is semantically equivalent to Class _Nonnull.

A nullable class can be used as Option<&AnyClass>.

See Apple’s documentation.

Implementations§

source§

impl AnyClass

source

pub fn get(name: &str) -> Option<&'static Self>

Returns the class definition of a specified class, or None if the class is not registered with the Objective-C runtime.

source

pub fn classes() -> Malloc<[&'static Self]>

Available on crate feature malloc only.

Obtains the list of registered class definitions.

source

pub fn classes_count() -> usize

Returns the total number of registered classes.

source

pub fn name(&self) -> &str

Returns the name of the class.

source

pub fn superclass(&self) -> Option<&AnyClass>

Returns the superclass of self, or None if self is a root class.

source

pub fn metaclass(&self) -> &Self

Returns the metaclass of self.

source

pub fn instance_size(&self) -> usize

Returns the size of instances of self.

source

pub fn instance_method(&self, sel: Sel) -> Option<&Method>

Returns a specified instance method for self, or None if self and its superclasses do not contain an instance method with the specified selector.

source

pub fn class_method(&self, sel: Sel) -> Option<&Method>

Returns a specified class method for self, or None if self and its superclasses do not contain a class method with the specified selector.

Same as cls.metaclass().class_method().

source

pub fn instance_variable(&self, name: &str) -> Option<&Ivar>

Returns the ivar for a specified instance variable of self, or None if self has no ivar with the given name.

source

pub fn instance_methods(&self) -> Malloc<[&Method]>

Available on crate feature malloc only.

Describes the instance methods implemented by self.

source

pub fn conforms_to(&self, proto: &AnyProtocol) -> bool

Checks whether this class conforms to the specified protocol.

source

pub fn adopted_protocols(&self) -> Malloc<[&AnyProtocol]>

Available on crate feature malloc only.

Get a list of the protocols to which this class conforms.

source

pub fn instance_variables(&self) -> Malloc<[&Ivar]>

Available on crate feature malloc only.

Describes the instance variables declared by self.

source

pub fn responds_to(&self, sel: Sel) -> bool

Check whether instances of this class respond to the given selector.

This doesn’t call respondsToSelector:, but works entirely within the runtime, which means it’ll always be safe to call, but may not return exactly what you’d expect if respondsToSelector: has been overwritten.

That said, it will always return true if an instance of the class responds to the selector, but may return false if they don’t directly (e.g. does so by using forwarding instead).

source

pub fn verify_sel<A, R>(&self, sel: Sel) -> Result<(), VerificationError>where A: EncodeArguments, R: EncodeConvertReturn,

Verify argument and return types for a given selector.

This will look up the encoding of the method for the given selector and return a VerificationError if any encodings differ for the arguments A and return type R.

Example
let cls = class!(NSObject);
let sel = sel!(isKindOfClass:);
// Verify that `isKindOfClass:`:
// - Exists on the class
// - Takes a class as a parameter
// - Returns a BOOL
let result = cls.verify_sel::<(&AnyClass,), bool>(sel);
assert!(result.is_ok());

Trait Implementations§

source§

impl Debug for AnyClass

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for AnyClass

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for AnyClass

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> MessageReceiver for &'a AnyClass

source§

unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Rwhere A: MessageArguments, R: EncodeConvertReturn,

Sends a message to the receiver with the given selector and arguments. Read more
source§

unsafe fn send_super_message<A, R>( self, superclass: &AnyClass, sel: Sel, args: A ) -> Rwhere A: MessageArguments, R: EncodeConvertReturn,

Sends a message to a specific superclass with the given selector and arguments. Read more
source§

impl PartialEq<AnyClass> for AnyClass

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RefEncode for AnyClass

source§

const ENCODING_REF: Encoding = Encoding::Class

The Objective-C type-encoding for a reference of this type. Read more
source§

impl Eq for AnyClass

source§

impl RefUnwindSafe for AnyClass

source§

impl Send for AnyClass

source§

impl Sync for AnyClass

source§

impl UnwindSafe for AnyClass

Auto Trait Implementations§

§

impl !Unpin for AnyClass

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> AutoreleaseSafe for Twhere T: ?Sized,