Injectios
Injectios

Reputation: 2797

Sharpie binding objective-c @protocols issue

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

Upvotes: 6

Views: 1237

Answers (2)

Alejandro Ruiz Varela
Alejandro Ruiz Varela

Reputation: 591

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

Upvotes: 5

Cheesebaron
Cheesebaron

Reputation: 24460

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.

Upvotes: -3

Related Questions