This document lists some useful tips and tricks when using Monobjc. It also lists some common pitfalls you may encounter.

Tips

  • Objective-C class are seen as class in .NET. These class are mostly a wrapper to forward method call to underlying native instance.
  • Objective-C protocols are seen as interface in .NET. This choice is close to what a protocol (formal or informal) represents: a contract. Note that class methods defined in Objective-C protocols are not available in .NET, as the later lacks this feature.
  • There is limited support for Objective-C categories. As .NET 3.5 offers extension methods, there is a way to provide Objective-C categories. Note that due to current implementation of the extension methods in .NET, only instance methods are supported (no static methods, no properties, no events).

Pitfalls

  • Don't try to create an object by invoking the InitWith methods directly, unless you know what you are doing. Most of these methods are called properly (alloc/initWith) by using the .NET constructors.
  • You are strongly advised not to create a new root class with the Monobjc bridge. As the Monobjc bridge relies on the alloc/dealloc calls to manage the wrappers lifecycle, a new root class would imply a lot of hassle (if you have to do it, start with the NSObject or the NSProxy wrapper). But honestly, do you really need a new root class as Monobjc bridge provides a NSObject and a NSProxy wrapper ?
  • You cannot create a new protocol with the Monobjc bridge. This is a limitation of the Objective-C runtime API. There is no API that allow the creation of new protocol or the assignement of a protocol to a class.