objc2 icon indicating copy to clipboard operation
objc2 copied to clipboard

Allow returning `Id` from `extern_methods!`

Open madsmtm opened this issue 1 year ago • 0 comments

WIP.

Example syntax:

extern_methods!(
    unsafe impl MyObject {
        #[sel_id(init)]
        fn new() -> Id<Self, Owned>;

        #[sel_id(description)]
        fn get(&self) -> Id<NSString, Owned>;
    }
);

// Becomes
impl MyObject {
    #[sel_id(init)]
    fn new() -> Id<Self, Owned> {
        // Automatic allocation?
        unsafe { msg_send_id![msg_send_id![Self::class(), alloc], init] }
    }

    #[sel_id(description)]
    fn get(&self) -> Id<NSString, Owned> {
        unsafe { msg_send_id![self, description] }
    }
}

madsmtm avatar Aug 15 '22 13:08 madsmtm