Protocol binding

rjmrjm CAMember ✭✭✭
edited February 2013 in Xamarin.iOS

I'm creating a binding for the MMTabBarView project.

Tab bar items are defined in a protocol:

@protocol MMTabBarItem <NSObject>
@optional
@property (copy) NSString *title;
// etc...
@end

We implement that protocol in a model type:

@interface DemoFakeModel : NSObject <MMTabBarItem> {
    NSString *_title;
    // etc...

So, I bind MMTabBarItem as per the documentation:

[BaseType (typeof(NSObject))]
[Model]
interface MMTabBarItem 
{
    [Export ("title", ArgumentSemantic.Copy)]
    NSString Title { get; set; }
}

And then create my model:

public class DemoModel : MMTabBar.MMTabBarItem
{
    [Export("title")]
    public override NSString Title { get; set; }
}

This works; however the framework does a check like this:

if ([item conformsToProtocol:@protocol(MMTabBarItem)])...

And confirmsToProtocol returns false. If I comment out the check, everything works as expected - so my binding is fine!

Have I missed something? Or is this type of behavior not supported (i.e. C# types conforming to a protocol, and that conformance being visible to Cocoa)?

Thanks!

Best Answer

Answers

Sign In or Register to comment.