Skip to content

Commit

Permalink
Document the associated function class
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jul 16, 2022
1 parent ac378d4 commit 1ac9617
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions objc2-foundation/src/declare_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ macro_rules! declare_class {

// Creation
impl $name {
#[doc = concat!(
"Get a reference to the Objective-C class `",
stringify!($name),
"`.",
"\n\n",
"May register the class if it wasn't already.",
)]
// TODO: Allow users to configure this?
$v fn class() -> &'static $crate::objc2::runtime::Class {
// TODO: Use `core::cell::LazyCell`
use $crate::__std::sync::Once;
Expand Down
18 changes: 18 additions & 0 deletions objc2-foundation/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
/// The traits [`objc2::RefEncode`] and [`objc2::Message`] are implemented to
/// allow sending messages to the object and using it in [`objc2::rc::Id`].
///
/// An associated function `class` is created on the object as a convenient
/// shorthand so that you can do `MyObject::class()` instead of
/// `class!(MyObject)`.
///
/// [`Deref`] and [`DerefMut`] are implemented and delegate to the first
/// superclass (direct parent). Auto traits are inherited from this superclass
/// as well (this macro effectively just creates a newtype wrapper around the
Expand Down Expand Up @@ -96,6 +100,13 @@ macro_rules! extern_class {
}

impl $name {
#[doc = concat!(
"Get a reference to the Objective-C class `",
stringify!($name),
"`.",
)]
#[inline]
// TODO: Allow users to configure this?
$v fn class() -> &'static $crate::objc2::runtime::Class {
$crate::objc2::class!($name)
}
Expand Down Expand Up @@ -169,6 +180,13 @@ macro_rules! __inner_extern_class {
}

impl<$($t $(: $b)?),*> $name<$($t),*> {
#[doc = concat!(
"Get a reference to the Objective-C class `",
stringify!($name),
"`.",
)]
#[inline]
// TODO: Allow users to configure this?
$v fn class() -> &'static $crate::objc2::runtime::Class {
$crate::objc2::class!($name)
}
Expand Down
2 changes: 2 additions & 0 deletions objc2-foundation/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ __inner_extern_class! {
}

impl NSObject {
/// Get a reference to the Objective-C class `NSObject`.
#[inline]
pub fn class() -> &'static Class {
class!(NSObject)
}
Expand Down

0 comments on commit 1ac9617

Please sign in to comment.