I'm just wondering why delegate in binding iOS project has to use BaseType(typeof(NSObject)) attribute when it's iOS counterpart does not use NSObject
iOS code:
@protocol TestDelegate
- (void)onSuccess:(NSString*)token;
@end
@interface Utility : NSObject
@property (nullable, weak, getter = getTestDelegate, setter = setTestDelegate:) id<TestDelegate> delegate;
@end
Sharpie code with delegate to event mapping added:
[Protocol, Model]
public interface TestDelegate
{
[Export ("onSuccess:")]
void OnSuccess (string token);
}
[BaseType(typeof(NSObject),
Delegates = new string[] { "WeakDelegate" },
Events = new Type[] { typeof(TestDelegate) })
public interface Utility
{
[Wrap ("WeakDelegate")]
[NullAllowed]
TestDelegate Delegate { [Bind ("getTestDelegate")] get; [Bind ("setTestDelegate:")] set; }
[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { [Bind ("getTestDelegate")] get; [Bind ("getTestDelegate:")] set; }
}
BaseType attribute was not generated on TestDelegate by Sharpie because iOS native code was not using <NSObject
> in its protocol.
This fails with "The type or namespace name TestDelegate' does not exist in the namespace
Test'. Are you missing an assembly reference? (CS0234) (Test.iOS)".
When I add [BaseType(typeof(NSObject))] on top of the TestDelegate it works like a charm.
The question is why this is needed?