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

Get Object from Class? #106

Closed
mikeumus opened this issue Sep 3, 2021 · 1 comment
Closed

Get Object from Class? #106

mikeumus opened this issue Sep 3, 2021 · 1 comment

Comments

@mikeumus
Copy link

mikeumus commented Sep 3, 2021

Hi @SSheldon 👋😀,

Thanks for this awesome library! I'd sponsor it if you turned on GitHub Sponsors 💖
Also, GitHub Discussion is a nice feature and would probably be better for the question I'm asking here:

Can you get an Object from a Class or can you only go the other direction?

Thank you, 🙇🏻‍♂️

@madsmtm
Copy link

madsmtm commented Sep 3, 2021

You can't really, since there is not a one-to-one relationship between these two. An object has one class, but a class can have many objects (called instances).

You can however create a new object from a class by simply sending new to the class, if that's what you're asking:

let cls = class!(NSObject);
let obj: Object = msg_send![cls, new];

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