Obj-C:实现自定义子类的委托
在 ASIHTTPRequest
文档 中,它说:
对于更复杂的情况,或者您想要在后台解析响应的情况,请为每种类型的请求创建 ASIHTTPRequest 的最小子类,并覆盖 requestFinished: 和 failureWithError:。
因此,我创建了一个最小的子类 MyRequest
,它将在后台线程中处理解析。我没有重写 ASIHTTPRequestDelegate
,因此我的委托类实现了该协议。但是,这些委托方法会传递 ASIHTTPRequest
(我希望将其视为)MyRequest
,以利用新功能。使用 Objective-C 的继承规则来处理这个问题的正确方法是什么?
In the ASIHTTPRequest
documentation, it says:
For more complex situations, or where you want to parse the response in the background, create a minimal subclass of ASIHTTPRequest for each type of request, and override requestFinished: and failWithError:.
So I've created a minimal subclass MyRequest
that will handle parsing in a background thread. I haven't overridden ASIHTTPRequestDelegate
, so my delegate class implements that protocol. However, those delegate methods pass a ASIHTTPRequest
, which is (and I'd like to be treated as) a MyRequest
, to take advantage of the new functionality. What's the right way to handle this with Objective-C's inheritance rules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
委托大概知道它正在使用
MyRequest
。在这种情况下,它可以在方法主体中进行检查强制转换:The delegate presumably knows it's working with a
MyRequest
. In that case, it can do a checked cast in the body of the method: