1

I followed each steps carefully in Walkthrough: Binding an iOS Objective-C Library

TestBindings project's build result is succeeded.

However, I got empty namespace references.

Empty namespace

My development environment settings is :

  1. Windows 10 Pro 1909
  2. Visual Studio 2019 Professional Version 16.6.0
  3. macOS Catalina 10.15.5
  4. XCode Version 11.4.1

Project structure is :

Project Structure

and each source code is :

ApiDefinition.cs

using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;

namespace TestBindings
{
    // @interface InfColorBarView : UIView
    [BaseType(typeof(UIView))]
    interface InfColorBarView
    {
    }

    // @interface InfColorBarPicker : UIControl
    [BaseType(typeof(UIControl))]
    interface InfColorBarPicker
    {
        // @property (nonatomic) float value;
        [Export("value")]
        float Value { get; set; }
    }

    // @interface InfColorIndicatorView : UIView
    [BaseType(typeof(UIView))]
    interface InfColorIndicatorView
    {
        // @property (nonatomic) UIColor * color;
        [Export("color", ArgumentSemantic.Assign)]
        UIColor Color { get; set; }
    }

    // @interface InfColorPickerController : UIViewController
    [BaseType(typeof(UIViewController))]
    interface InfColorPickerController
    {
        // +(InfColorPickerController *)colorPickerViewController;
        [Static]
        [Export("colorPickerViewController")]
        // [Verify(MethodToProperty)]
        InfColorPickerController ColorPickerViewController { get; }

        // +(CGSize)idealSizeForViewInPopover;
        [Static]
        [Export("idealSizeForViewInPopover")]
        // [Verify(MethodToProperty)]
        CGSize IdealSizeForViewInPopover { get; }

        // -(void)presentModallyOverViewController:(UIViewController *)controller;
        [Export("presentModallyOverViewController:")]
        void PresentModallyOverViewController(UIViewController controller);

        // @property (nonatomic) UIColor * sourceColor;
        [Export("sourceColor", ArgumentSemantic.Assign)]
        UIColor SourceColor { get; set; }

        // @property (nonatomic) UIColor * resultColor;
        [Export("resultColor", ArgumentSemantic.Assign)]
        UIColor ResultColor { get; set; }

        [Wrap("WeakDelegate")]
        InfColorPickerControllerDelegate Delegate { get; set; }

        // @property (nonatomic, weak) id<InfColorPickerControllerDelegate> delegate;
        [NullAllowed, Export("delegate", ArgumentSemantic.Weak)]
        NSObject WeakDelegate { get; set; }
    }

    // @protocol InfColorPickerControllerDelegate
    [BaseType(typeof(NSObject))]
    [Model]
    interface InfColorPickerControllerDelegate
    {
        // @optional -(void)colorPickerControllerDidFinish:(InfColorPickerController *)controller;
        [Export("colorPickerControllerDidFinish:")]
        void ColorPickerControllerDidFinish(InfColorPickerController controller);

        // @optional -(void)colorPickerControllerDidChangeColor:(InfColorPickerController *)controller;
        [Export("colorPickerControllerDidChangeColor:")]
        void ColorPickerControllerDidChangeColor(InfColorPickerController controller);
    }

    // @interface InfColorPickerNavigationController : UINavigationController
    [BaseType(typeof(UINavigationController))]
    interface InfColorPickerNavigationController
    {
    }

    // @interface InfColorSquareView : UIImageView
    [BaseType(typeof(UIImageView))]
    interface InfColorSquareView
    {
        // @property (nonatomic) float hue;
        [Export("hue")]
        float Hue { get; set; }
    }

    // @interface InfColorSquarePicker : UIControl
    [BaseType(typeof(UIControl))]
    interface InfColorSquarePicker
    {
        // @property (nonatomic) float hue;
        [Export("hue")]
        float Hue { get; set; }

        // @property (nonatomic) CGPoint value;
        [Export("value", ArgumentSemantic.Assign)]
        CGPoint Value { get; set; }
    }

    // @interface InfSourceColorView : UIControl
    [BaseType(typeof(UIControl))]
    interface InfSourceColorView
    {
        // @property (nonatomic) BOOL trackingInside;
        [Export("trackingInside")]
        bool TrackingInside { get; set; }
    }

    // @interface TestBindings : NSObject
    [BaseType(typeof(NSObject))]
    interface TestBindings
    {
    }
}

Structs.cs

using System;
using System.Runtime.InteropServices;
using CoreGraphics;

namespace TestBindings
{
    static class CFunctions
    {
        // extern float pin (float minValue, float value, float maxValue);
        [DllImport("__Internal")]
        // [Verify(PlatformInvoke)]
        static extern float pin(float minValue, float value, float maxValue);

        // extern void HSVtoRGB (float h, float s, float v, float *r, float *g, float *b);
        [DllImport("__Internal")]
        // [Verify(PlatformInvoke)]
        static extern unsafe void HSVtoRGB(float h, float s, float v, float* r, float* g, float* b);

        // extern void RGBToHSV (float r, float g, float b, float *h, float *s, float *v, BOOL preserveHS);
        [DllImport("__Internal")]
        // [Verify(PlatformInvoke)]
        static extern unsafe void RGBToHSV(float r, float g, float b, float* h, float* s, float* v, bool preserveHS);

        // extern CGImageRef createSaturationBrightnessSquareContentImageWithHue (float hue);
        [DllImport("__Internal")]
        // [Verify(PlatformInvoke)]
        static extern unsafe CGImage createSaturationBrightnessSquareContentImageWithHue(float hue);

        // extern CGImageRef createHSVBarContentImage (InfComponentIndex barComponentIndex, float *hsv);
        [DllImport("__Internal")]
        // [Verify(PlatformInvoke)]
        static extern unsafe CGImage createHSVBarContentImage(InfComponentIndex barComponentIndex, float[] hsv);

    }

    public enum InfComponentIndex : uint
    {
        Hue = 0,
        Saturation = 1,
        Brightness = 2
    }
}

libTestBindings.linkwith.cs

using System;
using ObjCRuntime;

[assembly: LinkWith ("libTestBindings.a", LinkTarget.ArmV7, SmartLink = true, ForceLoad = true)]

libTestBindings.a

libTestBindings.a properties

MAC OS

Xcode Project Settings Xcode Project Settings

Makefile Makefile

Folder Folder

ibocon
  • 1,352
  • 3
  • 17
  • 40

1 Answers1

1

Native Binding Project Compiles Library With No Methods Or Classes

Fixed the problem. The issue was that the Binding Project was in the same solution as the Xamarin.iOS project so it was not referencing the project correctly. Removed the binding project from the solution, then added the binding project DLL as a reference and now it properly sees the namespace and the methods. I will fix the other issues you mentioned like required frameworks. Thanks for your help! This issue can be closed.

This page helped:

https://forums.xamarin.com/discussion/81795/ios-obj-c-binding-cant-see-namespace

ibocon
  • 1,352
  • 3
  • 17
  • 40