Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS to C# what is equivalent of id<>

Tags:

c#

ios

xamarin

I got a IOS code to rewrite in c# that has this id<UIGestureRecognizerDelegate> gestureDelegate;

How can i rewrite this in c#?

@property (weak, nonatomic) id<UIGestureRecognizerDelegate> gestureDelegate;

Actually I declare it like UIGestureRecognizerDelegate gestureDelegate; but is it right? If i understand it right, id is like var in C#? If that's so how can i declare it as class parameters?

like image 394
Leze Avatar asked Dec 02 '25 15:12

Leze


1 Answers

The C# interface is like protocol in Objective-C, id<UIGestureRecognizerDelegate> means the object implements the methods defined in UIGestureRecognizerDelegate. So the same thing in C# could be (main idea, not tested in IDE):

interface UIGestureRecognizerDelegate {
   public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer);
}

class Example {
   public UIGestureRecognizerDelegate gestureDelegate; //the equivalent
}

And a class which conforms to the interface:

public class ExampleViewController:UIViewController,UIGestureRecognizerDelegate {
   var example = Example();

   public ExampleViewController() {
       this.example.gestureDelegate = this;
   }

   //implements the methods of interface UIGestureRecognizerDelegate
   public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer) {
       //......
   }
}
like image 114
Yun CHEN Avatar answered Dec 04 '25 07:12

Yun CHEN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!