Skip to content

Build failed when override a method in define_class! with return Option<Retained<UIView>> #728

@jyc5120

Description

@jyc5120

Tauri Wry is using the Objc2 in iOS/Mac platform,
We are try to disable the input Accessory View in the iOS, so we override the method by define_class!

define_class!(
  #[unsafe(super(WKWebView))]
  #[name = "WryWebView"]
  #[ivars = WryWebViewIvars]
  pub struct WryWebView;

  /// Overridden NSView methods.
  impl WryWebView {
    #[cfg(target_os = "ios")]
    #[unsafe(method(inputAccessoryView))]
    fn input_accessory_view(&self) -> Option<Retained<UIView>> {
      Option::None
    }
  } 

we can see the method in the UIResponder.rs objc2_generated repo. but the build complained error:

 / define_class!(
36  | |   #[unsafe(super(WKWebView))]
37  | |   #[name = "WryWebView"]
38  | |   #[ivars = WryWebViewIvars]
...   |
118 | | );
    | | ^
    | | |
    | |_the trait `OptionEncode` is not implemented for `Retained<objc2_ui_kit::UIView>`
    |   required by a bound introduced by this call
    |
    = help: the following other types implement trait `OptionEncode`:
              &T
              &mut T
              NonNull<T>
              NonZero<i16>
              NonZero<i32>
              NonZero<i64>
              NonZero<i8>
              NonZero<isize>
            and 138 others
    = note: required for `Option<Retained<objc2_ui_kit::UIView>>` to implement `Encode`
    = note: required for `Option<Retained<objc2_ui_kit::UIView>>` to implement `EncodeReturn`
    = note: required for `extern "C-unwind" fn(&WryWebView, Sel) -> Option<Retained<UIView>>` to implement `MethodImplementation`
note: required by a bound in `ClassBuilderHelper::<T>::add_method`

Please help us how can we do that

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesquestionThere is no such thing as a dumb one!

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions