Forward declarations in Objective-C headers and Xamarin.iOS

Luc MOUSSIEGT 1 Reputation point
2022-01-12T17:42:40.653+00:00

Hi everyone,

I've been working recently on integrating an Objective-C framework in a Xamarin.iOS application. The framework was not delivered through CocoaPads but directly as a zip archive, containing the .framework folder. The framework itself looks very similar to this one.

The main issue I have is that one header from this framework contains forward declarations ( @class statements) of classes whose definitions are missing from the public headers. I don't know whether this is expected from Objective Sharpie or not, but the ApiDefinitions.cs files contains no interface corresponding to those forward declared classes and as a result, other classes that have properties of those type can't be built. Example:

Objective-C header

@class SecretViewController;

@protocol MainViewControllerDelegate <NSObject>
@property (nonatomic, weak) SecretViewController* secretController;
@end

Resulting ApiDefinitions.cs generated by Objective Sharpie

[Protocol, Model (AutoGeneratedName = true)]
[BaseType (typeof(NSObject))]
interface MainViewControllerDelegate
{
    // @required @property (nonatomic, weak) SecretViewController * secretController
    [Abstract]
    [Export ("secretController", ArgumentSemantic.Weak)]
    SecretViewController secretController { get; set; }
}

But of course, this can't be built successfully. I get a CS0246 error: The type or namespace 'SecretViewController' could not be found (are you missing a using directive or an assembly reference?)

How am I supposed to adapt these kind of declarations in the binding project? I have no access to the internal code of the framework.

Developer technologies | .NET | Xamarin
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.