我正在使用sharpie
bind
命令为iOS
xamarin
库获取API接口
sharpie bind --namespace=XXX --sdk=iphoneos9.2 Headers/*.h
遇到@protocol
绑定问题:
The type or namespace name `IProfileDelegate' could not be found. Are you missing an assembly reference?
这是它的生成方式:
interface XLibrary : IProfileDelegate
{
[Wrap ("WeakProfileDelegate")]
[NullAllowed]
MB_ProfileDelegate ProfileDelegate { get; set; }
我明白它会创建空ProfileDelegate
然后编译器或用方法填充它但我的问题是找不到IProfileDelegate
。
@protocol ProfileDelegate <NSObject>
@required
- (void)GetProfileFinished:(NSString*)_data;
- (void)SetProfileFinished:(NSString*)_data;
@end
此处的区别在于I
符号(我猜为@protocols保留)。
如何使sharpie
生成正确的api定义?
我能够删除所有I
前缀并成功编译,但我宁愿修复它,不要在每次需要更新源库时重复此操作。
由于
答案 0 :(得分:3)
请记住,所有obj-c协议都充当接口或抽象类,我建议将#34;协议,模型和基本类型设置为nsobject,另一个所有的方法或属性都作为&#34;所需&#34;你需要将它指定为Abstract
[Protocol, Model]
[BaseType (typeof(NSObject))]
interface myAwesomeDelegate
{
[Abstract]
[Export(...)]
void myRequiredMethod(uint param1)
[Export(...)]
void anotherMethod()
}
希望这可以帮助您解决问题
答案 1 :(得分:-3)
根据Objective Sharpie documentation:
在某些情况下,这些生成的文件可能就是您所需要的,但是开发人员通常需要手动修改这些生成的文件以修复工具无法自动处理的任何问题(例如标记为{{ 3}})。
这意味着您有时必须调整两个生成的文件ApiDefinitions.cs和StructsAndEnums.cs来修复问题,例如本例中的问题。
您可以阅读有关Objective-C协议的绑定如何工作的更多信息,这些协议与C#接口类似,但不完全Verify attribute。