Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding protocol fails to pass conformsToProtocol
    text
    copied!<p>Using Xamarin to create a binding library for some external code, I've encountered a problem where despite (as far as I can tell) implementing all of the selectors in a protocol, in Obj-C code, my delegate fails to pass a <code>conformsToProtocol</code> check and, as a result, the code doesn't work.</p> <p>Here's what the Objective-C header file looks like (<a href="https://github.com/janrain/jump.ios/blob/master/Janrain/JRCapture/Classes/JRCapture.h" rel="nofollow">https://github.com/janrain/jump.ios/blob/master/Janrain/JRCapture/Classes/JRCapture.h</a>):</p> <pre><code>@protocol JRCaptureDelegate &lt;NSObject&gt; @optional - (void)engageAuthenticationDialogDidFailToShowWithError:(NSError *)error; - (void)engageAuthenticationDidCancel; - (void)engageAuthenticationDidSucceedForUser:(NSDictionary *)engageAuthInfo forProvider:(NSString *)provider; - (void)engageAuthenticationDidFailWithError:(NSError *)error forProvider:(NSString *)provider; - (void)captureSignInDidSucceedForUser:(JRCaptureUser *)captureUser status:(JRCaptureRecordStatus)captureRecordStatus; - (void)captureSignInDidFailWithError:(NSError *)error; - (void)registerUserDidSucceed:(JRCaptureUser *)registeredUser; - (void)registerUserDidFailWithError:(NSError *)error; - (void)refreshAccessTokenDidSucceedWithContext:(id &lt;NSObject&gt;)context; - (void)refreshAccessTokenDidFailWithError:(NSError *)error context:(id &lt;NSObject&gt;)context; @end </code></pre> <p>And here's the part of the <code>ApiDefinition.cs</code> that corresponds to it:</p> <pre><code>[Model, BaseType (typeof (NSObject))] public partial interface JRCaptureDelegate { [Export ("engageAuthenticationDidCancel")] void EngageAuthenticationCancelled (); [Export ("engageAuthenticationDidSucceedForUser:forProvider:")] void AuthenticationSucceededForProvider (NSDictionary engageAuthInfo, string provider); [Export ("captureSignInDidSucceedForUser:status:")] void SignInSucceeded (JRCaptureUser captureUser, JRCaptureRecordStatus captureRecordStatus); [Export ("registerUserDidSucceed:")] void RegisterUserSucceeded(JRCaptureUser registeredUser); [Export ("refreshAccessTokenDidSucceedWithContext:")] void RefreshAccessTokenSucceeded(NSObject context); //- (void)engageAuthenticationDialogDidFailToShowWithError:(NSError *)error [Export ("engageAuthenticationDialogDidFailToShowWithError:")] void DialogFailedToShow (NSError error); //- (void)engageAuthenticationDidFailWithError:(NSError *)error forProvider:(NSString *)provider; [Export("engageAuthenticationDidFailWithError:forProvider:")] void AuthenticationFailedForProvider (NSError error, NSString provider); //- (void)captureSignInDidFailWithError:(NSError *)error; [Export("captureSignInDidFailWithError:")] void SignInFailed (NSError error); //- (void)registerUserDidFailWithError:(NSError *)error; [Export("registerUserDidFailWithError:")] void RegisterUserFailed (NSError error); //- (void)refreshAccessTokenDidFailWithError:(NSError *)error context:(id &lt;NSObject&gt;)context; [Export("refreshAccessTokenDidFailWithError:context:")] void RefreshAccessTokenFailed (NSError error, NSObject context); } </code></pre> <p>This compiles and appears to work just fine except I was having a problem with one particular method that didn't appear to want to call the methods in my delegate class. After <em>a lot</em> of digging (and learning Objective-C the hard way), I believe I have isolated the problem. In the library I'm binding, I have this:</p> <pre><code> if ([delegate conformsToProtocol:@protocol(JRCaptureDelegate)] &amp;&amp; [delegate respondsToSelector:@selector(captureSignInDidSucceedForUser:status:)]) </code></pre> <p>And with a little <code>DLog</code>ing, I find that my delegate fails the <code>conformsToProtocol</code> check (although it does pass the <code>respondsToSelector</code> check). </p> <p>So why does my class fail <code>conformsToProtocol</code> when it does implement all the methods in the protocol. What am I missing here?</p> <p>My class implementing the delegate that gets passed to the various methods that take a <code>JRCaptureDelegate</code> just looks like this:</p> <pre><code>public class SignIn : JRCaptureDelegate { // overrides for each method } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload