Skip to content

Commit 7d74bf1

Browse files
committed
Use static linking in derived NSObject.
1 parent fbc0c91 commit 7d74bf1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

derive/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ pub fn impl_object(input: TokenStream) -> TokenStream {
1717

1818
// Build the impl
1919
let name = &ast.ident;
20+
let link_name = format!("OBJC_CLASS_$_{}", name);
21+
2022
let gen = quote! {
2123
unsafe impl ::objc::Message for #name { }
2224

2325
impl ::objc_foundation::INSObject for #name {
2426
fn class() -> &'static ::objc::runtime::Class {
25-
let name = stringify!(#name);
26-
match ::objc::runtime::Class::get(name) {
27-
Some(cls) => cls,
28-
None => panic!("Class {} not found", name),
27+
extern {
28+
#[link_name = #link_name]
29+
static OBJC_CLASS: ::objc::runtime::Class;
30+
}
31+
unsafe {
32+
&OBJC_CLASS
2933
}
3034
}
3135
}

0 commit comments

Comments
 (0)