gpt4 book ai didi

xamarin - Objective Sharpie 有时会将 I 添加到 @protocols

转载 作者:行者123 更新时间:2023-12-05 04:12:30 34 4
gpt4 key购买 nike

我正在尝试绑定(bind)一个库,我遇到了这个问题:

// @interface PTPusher : NSObject <PTPusherConnectionDelegate, PTPusherEventBindings>
[BaseType(typeof(NSObject))]
interface PTPusher : IPTPusherConnectionDelegate, IPTPusherEventBindings

找不到 IPTPusherConnectionDelegateIPTPusherEventBindings,但它们未更改的名称确实存在:

// @protocol PTPusherConnectionDelegate <NSObject>
[Protocol, Model]
[BaseType(typeof(NSObject))]
interface PTPusherConnectionDelegate

为什么 Objective Sharpie 在继承接口(interface)列表中添加 I,而不是在接口(interface)名称本身中?

我应该更改什么来解决这个问题?我是将 I 添加到接口(interface)名称还是从继承的接口(interface)列表中删除 I?或者我可以在不更改这些的情况下解决这个问题,而只是通过向这些类/接口(interface)添加或删除属性来解决这个问题吗?

最佳答案

Starting with MonoTouch 7.0 a new and improved protocol binding functionality has been incorporated. Any definition that contains the [Protocol] attribute will actually generate three supporting classes that vastly improve the way that you consume protocols:

// Full method implementation, contains all methods
class MyProtocol : IMyProtocol {
public void Say (string msg);
public void Listen (string msg);
}

// Interface that contains only the required methods
interface IMyProtocol: INativeObject, IDisposable {
[Export ("say:”)]
void Say (string msg);
}

// Extension methods
static class IMyProtocol_Extensions {
public static void Optional (this IMyProtocol this, string msg);
}
}

此外,

If you want to use the protocol definitions in your API, you will need to write skeleton empty interfaces in your API definition. If you want to use the MyProtocol in an API, you would need to do this:

[BaseType (typeof (NSObject))]
[Model, Protocol]
interface MyProtocol {
// Use [Abstract] when the method is defined in the @required section
// of the protocol definition in Objective-C
[Abstract]
[Export ("say:")]
void Say (string msg);

[Export ("listen")]
void Listen ();
}

interface IMyProtocol {}

[BaseType (typeof(NSObject))]
interface MyTool {
[Export ("getProtocol")]
IMyProtocol GetProtocol ();
}

来源:https://developer.xamarin.com/guides/cross-platform/macios/binding/binding-types-reference/#Protocols

关于xamarin - Objective Sharpie 有时会将 I 添加到 @protocols,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40280938/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com