Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting to Object #11

Open
ferranpujolcamins opened this issue May 10, 2020 · 1 comment
Open

Casting to Object #11

ferranpujolcamins opened this issue May 10, 2020 · 1 comment

Comments

@ferranpujolcamins
Copy link

ferranpujolcamins commented May 10, 2020

How can I cast a INSObject to a objc::runtime::Object?

@madsmtm
Copy link

madsmtm commented Jun 3, 2021

INSObject is a trait, so, you wouldn't.

But you can cast an implementation, e.g. NSObject or NSString:

let obj: Id<NSObject> = NSObject::new();
let obj_ref: &NSObject = &*obj;
let obj_ptr: *const NSObject = obj_ref;
let ptr: *const objc::runtime::Object = obj_ptr as *const objc::runtime::Object;

// Or short:
let obj = NSObject::new();
let ptr = &*obj as *const _ as *const objc::runtime::Object;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants