I'm porting the Official Apple Multipeer WiTap sample to Xamarin and C#, however I'm not sure how to port this method within TapViewController.
It contains all the things I'm not sure how to port... namely
- A delegate that is expressed only in code, and has no strong delegate in the Xamarin framework. (this is probably easy, just a concept I'm missing)
- What the heck is the
idhere, and how do I declare/use it? - How do I declare
self.delegate;
code:
- (IBAction)closeButtonAction:(id)sender
{
id <TapViewControllerDelegate> strongDelegate;
#pragma unused(sender)
strongDelegate = self.delegate;
if ([strongDelegate respondsToSelector:@selector(tapViewControllerDidClose:)]) {
[strongDelegate tapViewControllerDidClose:self];
}
}
Here is a link to my code, where the port is in progress
Are you attempting to port Objective-C code to C# without knowing the former?
idis Obj-C's "any object", whileid<protocolName>is any object which implements the specified protocol. An Obj-C "delegate" is just an object which implements a given protocol, it is the way it is used that makes it a delegate. Objc-C protocols and C# interfaces are matching concepts. SostrongDelegateis a variable whose type is a C# interface (which you've presumably translated from the Obj-C protocol).self.delegate: it's an Objc-C property reference with the same (or compatible) type asstrongDelegate. C# has properties.iftest in Obj-C is determine whether the referenced object implements the specified method and if so invokes it. Obj-C protocols allow optional methods, i.e. methods objects implementing the protocol need not implement. C# interfaces have no direct equivalent. In your translation of the Obj-C protocol to a C# interface you either made all optional methods non-optional, or you did something else. Translate theifto match whatever you did.HTH