objective-c - 如何使用 Objective Sharpie 绑定(bind) Objective-C 库中的 C 数组类型?

标签 objective-c c xamarin xamarin.ios objective-sharpie

我需要绑定(bind)的方法在原始数组中有参数,例如:

(bool)isRectangle:(const CGPoint[4])corners;

如何将 const CGPoint[4] 类型与 C# 类型绑定(bind)?

注意:使用Sharpie,结果如下

[Static]
[Export("isRectangle:")]
void IsRectangle(CGPoint[] corners);

当我构建它时,我收到错误

cannot convert from 'CoreGraphics.CGPoint[]' to 'Foundation.NSObject'

最佳答案

StructsAndEnums.cs 中将 const CGPoint[4] 定义为结构体:

[StructLayout(LayoutKind.Sequential)]
public struct Rectangle
{
    public CGPoint leftTop;
    public CGPoint rightTop;
    public CGPoint leftBotton;
    public CGPoint rightBotton;
}

您的定义变为:

//(bool)isRectangle:(const CGPoint[4])corners;
[Export("isRectangle:")]
bool IsRectangle(Rectangle corners);

关于objective-c - 如何使用 Objective Sharpie 绑定(bind) Objective-C 库中的 C 数组类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46210289/

相关文章:

xamarin - 无法升级 Xamarin.Android 的 nuget 包

iphone - 在接口(interface)文件 : when to use forward declaration for custom class as opposed to just including its header?

objective-c - NS 大纲 View : Expand all objects of a specific class only

c - 为什么要写 "while((void)0, 0)"这样的C代码

c++ - Mozilla C/C++ 编码风格

c++ - 为什么goto这个宏定义会导致程序崩溃?

objective-c - UIDatePicker 和 UIPickerView 的 UIView 或 UIViewController?

ios - 提高大型数据集上谓词的性能

c# - Xamarin - 多目标 - "' System.ValueTuple` 2' is declared in multiple referenced"

c# - Xamarin 形成具有可绑定(bind)属性的 ValueConverter