DocCaliban
DocCaliban

Reputation: 1094

Uderstanding Objective C delegates in MonoTouch Binding

Not having worked with Objective C before I thought I would give a stab @ creating a binding for a native library.

The native library has a Ctor that takes 7 arguments

  bob = [[Bob alloc] initWithFirstName:@"bob" 
       lastName:@"barker" 
       zipCode:@"123456"  
       userId:@"123456" 
       viewController:vc 
       debug:YES 
       delegate:self];

I have created the binding project, which includes the Bob class and the BobDelegate

Unfortunately at this point i am stumped... I don't really understand how delegate:self works, or how I would pass that in the Ctor.

It seems to me that Delegates work much differently in C#, and I am really at a loss to even start.

Upvotes: 1

Views: 534

Answers (1)

Anuj
Anuj

Reputation: 3134

You can think of delegates like C# interfaces, for now. As you'll discover they are different, but among other things, they are used as "contracts" between implementations.

We have created a sample that helps users understand common patterns for binding native obj-C components into C# using btouch. As well as some really good workflow for building the library in the project Makefile. You can check out the BindingSample project here:

https://github.com/xamarin/monotouch-samples/tree/master/BindingSample

Upvotes: 2

Related Questions