Forum Xamarin.Forms

Binding iOS protocol

GraverobberGraverobber Member ✭✭✭
edited October 2019 in Xamarin.Forms

Hi,

one should think that I understood Bindings by now, but whenever it comes to iOS I face new adventures.

I created an objective-c framework that contains just one single class which has a header and main file.
This file defines a protocol in its header.

#import <Foundation/Foundation.h>
@protocol MyDelegate <NSObject>
    @required
    -(void) method1:(NSInteger *)value;
    -(void) method2:(NSString*) value;
    -(void) method3:(NSString*) value;
@end
@interface MyClass : NSObject
    +(void)addDelegate:(id <MyDelegate>)delegate;
@end

Then I want to only bind the delegate, I don't care for the MyClass (for the moment).
So what I defined is

[Protocol, Model]
[BaseType(typeof(NSObject))]
interface MyDelegate
{
    [Abstract]
    [Export("method1:")]
    public void Method1(int value);

    [Abstract]
    [Export("method2:")]
    public void  Method(string value);

    [Abstract]
    [Export("method3:")]
    public void Method3(string value);
}

If I build the binding project all is fine. If I build the iOS project that integrates the binding, all is fine.
However the MyDelegate class simply doesn't appear in the iOS project. It is not existent.

If I remove the [Protocol,Model] from the top of the definition I get an error telling me the class MyDelegate couldn't be found.
But I can confirm 100% that the framework contains the corresponding header file.

What am I doing wrong here?

Thank you!

Best Answer

  • GraverobberGraverobber ✭✭✭
    edited October 2019 Accepted Answer

    So I changed my definition to this

    [BaseType(typeof(NSObject))]
    [Model][Protocol]
    interface MyDelegate
    

    and I removed the Abstract ones as well.

    VisualStudio tells me that it can not find the class and functions (marked as red) but it compiles and works fine now.

Answers

  • GraverobberGraverobber Member ✭✭✭
    edited October 2019 Accepted Answer

    So I changed my definition to this

    [BaseType(typeof(NSObject))]
    [Model][Protocol]
    interface MyDelegate
    

    and I removed the Abstract ones as well.

    VisualStudio tells me that it can not find the class and functions (marked as red) but it compiles and works fine now.

Sign In or Register to comment.