xamarinxamarin.iosobjective-sharpiexamarin-binding

Objective Sharpie sometimes adds I to @protocols


I am trying to bind a library, and I came across this issue:

// @interface PTPusher : NSObject <PTPusherConnectionDelegate, PTPusherEventBindings>
[BaseType(typeof(NSObject))]
interface PTPusher : IPTPusherConnectionDelegate, IPTPusherEventBindings

The IPTPusherConnectionDelegate and IPTPusherEventBindings could not be found, but their unchanged name does exist:

// @protocol PTPusherConnectionDelegate <NSObject>
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface PTPusherConnectionDelegate

Why does Objective Sharpie add the I in the list of inherited interfaces, but not in the interface name itself?

What am I supposed to change to fix this? Do I add the I to the interface name or do I remove the I from the inherited interfaces list? Or can I fix this without changing those, and just by adding or removing attributes to those classes/interfaces?


Solution

  • Starting with MonoTouch 7.0 a new and improved protocol binding functionality has been incorporated. Any definition that contains the [Protocol] attribute will actually generate three supporting classes that vastly improve the way that you consume protocols:

    // Full method implementation, contains all methods
    class MyProtocol : IMyProtocol {
        public void Say (string msg);
        public void Listen (string msg);
    }
    
    // Interface that contains only the required methods
    interface IMyProtocol: INativeObject, IDisposable {
        [Export ("say:”)]
        void Say (string msg);
    }
    
    // Extension methods
    static class IMyProtocol_Extensions {
        public static void Optional (this IMyProtocol this, string msg);
        }
    }
    

    Also,

    If you want to use the protocol definitions in your API, you will need to write skeleton empty interfaces in your API definition. If you want to use the MyProtocol in an API, you would need to do this:

    [BaseType (typeof (NSObject))]
    [Model, Protocol]
    interface MyProtocol {
        // Use [Abstract] when the method is defined in the @required section
        // of the protocol definition in Objective-C
        [Abstract]
        [Export ("say:")]
        void Say (string msg);
    
        [Export ("listen")]
        void Listen ();
    }
    
    interface IMyProtocol {}
    
    [BaseType (typeof(NSObject))]
    interface MyTool {
        [Export ("getProtocol")]
        IMyProtocol GetProtocol ();
    }
    

    Source: https://developer.xamarin.com/guides/cross-platform/macios/binding/binding-types-reference/#Protocols