Ios gomobile:ObjC的绑定回调
我有一个围棋界面Ios gomobile:ObjC的绑定回调,ios,objective-c,go,gomobile,Ios,Objective C,Go,Gomobile,我有一个围棋界面 type GetResponse interface { OnResult(json string) } 我必须使用这个接口从ObjC订阅OnResult事件 func Subscribe( response GetResponse){ response.OnResult("some json") } ObjC bind为我提供了一个相应的协议和一个基本类 @interface GetResponse : NSObject <goSeqRefInterface, Ge
type GetResponse interface { OnResult(json string) }
我必须使用这个接口从ObjC订阅OnResult事件
func Subscribe( response GetResponse){ response.OnResult("some json") }
ObjC bind为我提供了一个相应的协议和一个基本类
@interface GetResponse : NSObject <goSeqRefInterface, GetResponse> {
}
@property(strong, readonly) id _ref;
- (instancetype)initWithRef:(id)ref;
- (void)onResult:(NSString*)json;
@end
我有一个实体对象,没有明显的方法连接回调。如果我创建一个类别并覆盖onResult例程,则不会调用它。仅仅因为根据AppleDoc,重写类的现有方法并不是由行为决定的。无论何时从Go调用OnResult,都会调用默认实现并显示“Go RESULT”
有办法解决我的问题吗?或者我只是不太准确地告诉了医生?请帮助我我今天遇到了类似的问题。我认为这是gomobile中的一个bug,但毕竟是我对swift/objc的误解 该错误的TLDR是您必须对协议进行子类化,而不是接口。如果您使用的是swift,则可以将
GetResponseProtocol
子类化:
class MyResponse: GetResponseProtocol
如果在objc中,那么您可能希望直接实现GetResponse协议,而不是子类化接口
func Subscribe( response GetResponse){ response.OnResult("some json") }