Skip to content

objc2-ui-kit: trying to implement dropInteraction:sessionDidUpdate: on UIDropInteractionDelegate doesn't compile #750

Open
@httnn

Description

@httnn

when trying to create a UIDropInteractionDelegate like this:

define_class!(
    #[unsafe(super = NSObject)]
    #[thread_kind = MainThreadOnly]
    #[name = "Delegate"]
    struct Delegate;

    unsafe impl NSObjectProtocol for Delegate {}

    unsafe impl UIDropInteractionDelegate for Delegate {
        #[unsafe(method(dropInteraction:sessionDidUpdate:))]
        unsafe fn session_did_update(
            &self,
            interaction: &UIDropInteraction,
            session: &ProtocolObject<dyn UIDropSession>,
        ) -> Retained<UIDropProposal> {
            let mtm = MainThreadMarker::new().unwrap();
            let instance = UIDropProposal::alloc(mtm);
            UIDropProposal::initWithDropOperation(instance, UIDropOperation::Copy)
        }
}

the compiler tells me:

36  | / define_class!(
37  | |     #[unsafe(super = NSObject)]
38  | |     #[thread_kind = MainThreadOnly]
39  | |     #[name = "Delegate"]
...   |
110 | | );
    | |_^ the trait `Encode` is not implemented for `Retained<UIDropProposal>`

implement all other methods seems to work fine (but most don't return anything).

the issue can be worked around by returning a raw pointer:

#[unsafe(method(dropInteraction:sessionDidUpdate:))]
unsafe fn session_did_update(
    &self,
    interaction: &UIDropInteraction,
    session: &ProtocolObject<dyn UIDropSession>,
) -> *mut UIDropProposal {
    let mtm = MainThreadMarker::new().unwrap();
    let instance = UIDropProposal::alloc(mtm);
    Retained::into_raw(UIDropProposal::initWithDropOperation(instance, UIDropOperation::Copy))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesbugSomething isn't workingquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions