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?
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) {
//......
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With