I stumbled across a subtle gotcha while exploring binding Objective-C types in MonoTouch. As luck would have it, someone else did also and posted a question about it on the MonoTouch IRC channel. The poster of the question eventually came across the answer and shared it there, and I am going to post it here in case anyone else makes the same mistake and is looking for some answers.
I was following along with the documentation for binding new Objective-C types on the MonoTouch site, and as a way to ease into the binding process, I chose a class to define from the CloudMade SDK that I am looking to expose in MonoTouch. The class selected was the BBox class (bbox.h) and I went about creating the following API definition shown below:
using System; using MonoTouch.Foundation; using MonoTouch.ObjCRuntime; namespace CloudMade { [BaseType(typeof (NSObject))] interface BBox { [Export("westernLongitude")] float WesternLongitude {get;set;} [Export("southernLatitude")] float SouthernLatitude {get;set;} [Export("easternLongitude")] float EasternLongitude {get;set;} [Export("northerLatitude")] float NorthernLatitude {get;set;} [Export("asString")] string AsString(); } }
$ btouch BBox.cs /var/folders/E4/E44PAZnZGKGpVrmseo2N3++++TI/-Tmp-/9qgrm9nm.lnv/CloudMade/BBox.g.cs(46,71): error CS0117: `CloudMade.BBox' does not contain a definition for `Messaging' /var/folders/E4/E44PAZnZGKGpVrmseo2N3++++TI/-Tmp-/9qgrm9nm.lnv/CloudMade/BBox.g.cs(28,30): (Location of the symbol related to previous error) /var/folders/E4/E44PAZnZGKGpVrmseo2N3++++TI/-Tmp-/9qgrm9nm.lnv/CloudMade/BBox.g.cs(57,71): error CS0117: `CloudMade.BBox' does not contain a definition for `Messaging' /var/folders/E4/E44PAZnZGKGpVrmseo2N3++++TI/-Tmp-/9qgrm9nm.lnv/CloudMade/BBox.g.cs(28,30): (Location of the symbol related to previous error) Compilation failed: 2 error(s), 0 warnings btouch: API binding contains errors.
Do not give the file that the API definition is being saved in the same name as one of the interfaces that you are defining.
Steer clear of that and you’ll be binding Objective-C types with ease.
One Response
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Continuing the Discussion