Sharpie binding objective-c @protocols issue

安稳与你 提交于 2019-12-10 16:27:18

问题


I'm using sharpie bind command to get API interfaces for my iOS library for xamarin

sharpie bind --namespace=XXX --sdk=iphoneos9.2 Headers/*.h

Have issues with @protocol bindings:

The type or namespace name `IProfileDelegate' could not be found. Are you missing an assembly reference?

This is how it's generated:

    interface XLibrary : IProfileDelegate
    {
    [Wrap ("WeakProfileDelegate")]
    [NullAllowed]
    MB_ProfileDelegate ProfileDelegate { get; set; }

I understand that it creates empty ProfileDelegate then compiler or something fills it with methods BUT my issue is that IProfileDelegate not found.

@protocol ProfileDelegate <NSObject>
@required
- (void)GetProfileFinished:(NSString*)_data;
- (void)SetProfileFinished:(NSString*)_data;
@end

Difference here in I symbol (which is reserved for @protocols I guess). How to make sharpie generate proper api definitions?

I'm able to remove all I prefixes and it compiles successfully but I'd rather fix it not to repeat this every time I need to update source library.

Thanks


回答1:


Remember that all the obj-c protocol act as a interface or abstract class i recommend to put "protocol, model and set base type as nsobject, another thing all the methods or properties maked as a "required" you need to specify it as Abstract

[Protocol, Model]
[BaseType (typeof(NSObject))]
interface myAwesomeDelegate
{
  [Abstract]
  [Export(...)]
  void myRequiredMethod(uint param1)

  [Export(...)]
  void anotherMethod()
}

hope this will help you to fix your issue




回答2:


According to the Objective Sharpie documentation:

In some cases these generated files might be all you need, however more often the developer will need to manually modify these generated files to fix any issues that could not be automatically handled by the tool (such as those flagged with a Verify attribute).

This means you will sometimes have to adjust the two generated files, ApiDefinitions.cs and StructsAndEnums.cs to fix issues, such as the one in this case.

You can read more about how bindings work for Objective-C protocols, which are similar to C# Interfaces, but not quite in the binding documentation.



来源:https://stackoverflow.com/questions/36448006/sharpie-binding-objective-c-protocols-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!