macro_rules! class { ($name:ident) => { ... }; }
Expand description
Gets a reference to an AnyClass
from the given name.
If you have an object that implements ClassType
, consider using the
ClassType::class
method instead.
§Panics
Panics if no class with the given name can be found.
To dynamically check for a class that may not exist, use AnyClass::get
.
§Features
If the experimental "unstable-static-class"
feature is enabled, this
will emit special statics that will be replaced by dyld when the program
starts up.
Errors that were previously runtime panics may now turn into linker errors
if you try to use a class which is not available. Additionally, you may
have to call msg_send![cls, class]
on the result if you want to use it
in a dynamic context (e.g. dynamically declaring classes).
See the corresponding section in the sel!
macro for
more details on the limitations of this. The
"unstable-static-class-inlined"
corresponds to the
"unstable-static-sel-inlined"
feature here.
§Examples
Get and compare the class with one returned from ClassType::class
.
use objc2::runtime::NSObject;
use objc2::{class, ClassType};
let cls1 = class!(NSObject);
let cls2 = NSObject::class();
assert_eq!(cls1, cls2);
Try to get a non-existing class (this will panic, or fail to link).
use objc2::class;
let _ = class!(NonExistantClass);