Skip to content

Commit 68c1c2c

Browse files
committed
Make AnyObject.class return a static
1 parent 2434641 commit 68c1c2c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

crates/objc2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5050
`MethodImplementation` to `Return` and `Arguments`.
5151
* **BREAKING**: Make `rc::Allocated` allowed to be `NULL` internally, such
5252
that uses of `Option<Allocated<T>>` is now simply `Allocated<T>`.
53+
* `AnyObject::class` now returns a `'static` reference to the class.
5354

5455
### Deprecated
5556
* Soft deprecated using `msg_send!` without a comma between arguments (i.e.

crates/objc2/src/runtime/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,11 @@ impl AnyObject {
10521052

10531053
/// Dynamically find the class of this object.
10541054
#[doc(alias = "object_getClass")]
1055-
pub fn class(&self) -> &AnyClass {
1055+
pub fn class(&self) -> &'static AnyClass {
10561056
let ptr: *const AnyClass = unsafe { ffi::object_getClass(self.as_ptr()) }.cast();
1057-
// SAFETY: The class is not NULL because the object is not NULL.
1057+
// SAFETY: The class is not NULL because the object is not NULL, and
1058+
// it is safe as `'static` since classes are static, and it could be
1059+
// retrieved via. `AnyClass::get(self.class().name())` anyhow.
10581060
unsafe { ptr.as_ref().unwrap_unchecked() }
10591061
}
10601062

0 commit comments

Comments
 (0)