委托属性分配问题,RestKit RKRequest
我知道使用“分配”更好,但我有以防万一使用保留更好。
我通过创建 RKRequest 对象来调用 Web 服务。
RKRequest *request = [[RKClient sharedClient] get:urlString delegate:self];
请求对象本身由单例请求队列保留和管理,所以我不关心请求对象,只关心委托方法。
有处理请求结果的方法。
这些代码位于UIViewController中,而视图控制器本身就是委托。
如果视图控制器在请求处理期间被释放,RKRequest 会调用死指针的委托,并且程序崩溃。
所以我必须保留 RKRequest 并在视图控制器释放时将 nil 分配给委托。
此外,当请求成功或失败时,我必须释放 RKRequest。
但我不认为如果 RKRequest 将委托指针作为“保留”指针,我如何才能美丽地管理这些对象?
property "assign" and "retain" for delegate
I know use 'assign' is better, but I have in case that use retain is better.
I call web service by making RKRequest object.
RKRequest *request = [[RKClient sharedClient] get:urlString delegate:self];
request object itself is retained and managed by singleton request queue, so I don't care about request object and I concern about delegate methods only.
there's methods handle request results.
These codes are in UIViewController, and view controller itself is delegate.
If view controller is become dealloc during request is processing, RKRequest call delegate that is dead pointer and program crashes.
so I have to retain RKRequest and assign nil to delegate when view controller is dealloc.
furthermore, I have to release RKRequest when request is succeeded or failed.
but I don't think if RKRequest have delegate pointer as 'retain' pointer, how can I manage these objects BEAUTIFULLY?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所需要做的就是将以下调用添加到控制器 (RKRequestDelegate) dealloc 方法中:
All that's needed is to add the following call to your controller (RKRequestDelegate) dealloc method: