Search code examples
xamarin.iosprotocolsabstract-classobjective-sharpie

Xamarin iOS Binding - Protocol - Cannot Create Instance of Abstract Class


I've generated some binding code using Sharpie for the Zebra Scanner SDK.

Zebra Scanner SDK

The generated code builds fine once I've processed the [Verify] attributes.

The starting point for the SDK is to call a static method on the SDK factory which then should return the SDK Api object. The create SDK Api method is bound to a native call which I can't manipulate.

The SDK Api object is a protocol and the code generated by Sharpie is an abstract class.

So when trying to create the SDK Api object, as instructed through the API factory, I get a runtime exception Cannot create instance of an abstract class.

I'm a bit lost as to how to resolve this. Any thoughts or suggestions would be much appreciated.


Solution

  • You can read this document about protocols-with-xamarinios.

    Any class can provide annotation data by simply deriving from MKAnnotation, as long as at least the Coordinate property is implemented.

    Just create a new class that inherits from SDK Api objec and then initialize it with your data there.