如何子类化这个? DarwinRemote Objective C
我使用这个类:
@interface NSObject( WiiRemoteDiscoveryDelegate )
- (void) WiiRemoteDiscovered:(WiiRemote*)wiimote;
- (void) WiiRemoteDiscoveryError:(int)code;
@end;
但是我如何子类化它?
I use this class:
@interface NSObject( WiiRemoteDiscoveryDelegate )
- (void) WiiRemoteDiscovered:(WiiRemote*)wiimote;
- (void) WiiRemoteDiscoveryError:(int)code;
@end;
but how do I subclass this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这称为非正式协议,也是 Cocoa 框架在最近版本的 Mac OS X 之前主要声明委托方法的方式。
这段代码只是简单地说它将在某个对象上调用方法“WiiRemoteDiscovered:”和“WiiRemoteDiscoveryError:” 。类别“WiiRemoteDiscoveryDelegate”的名称表明它计划在委托上调用这些方法。
想象一下这样的代码:
如果您要构建它,您会在调用 WiiRemoteDiscoveryError: 的行上收到编译器警告:因为该方法尚未在任何地方声明。为了避免这种情况,您可以执行以下两种操作之一。您可以执行此类作者所做的操作,并将其添加到标头中:
该块基本上是说每个对象都实现 WiiRemoteDiscovered: (这不是真的),并使编译器警告静音。
或者你可以做一些更正式的事情,如下所示:
This is called an informal protocol, and is how the Cocoa frameworks primarily declared delegate methods before recent versions of Mac OS X.
This block of code is simply saying that it will invoke the methods "WiiRemoteDiscovered:" and "WiiRemoteDiscoveryError:" on some object. The name of the category "WiiRemoteDiscoveryDelegate" is your indication that it plans to invoke these methods on the delegate.
Imagine some code like this:
If you were to build that, you'd get a compiler warning on the line that invokes WiiRemoteDiscoveryError: because that method hasn't been declared anywhere. To avoid that you can do one of two things. You can do what the authors of this class did and add this to a header:
That block is basically saying that every object implements WiiRemoteDiscovered: (which isn't true), and silence the compiler warning.
Or you could do something more formal like this: