将 userInfo 添加到 NSURLConnection
对于我正在开发的一个项目,我需要使用 NSURLConnection 进行多个同时的 plist 上传,并且如果有一个 userInfo 属性来跟踪内容,那就太好了。
我有:
// header
@interface NSURLConnection ()
@property (nonatomic, retain) id userInfo;
@end
// implementation
@implementation NSURLConnection ()
@synthesize userInfo = _userInfo;
@end
当我尝试编译时,它说它需要括号中的标识符。当我给它一个标识符,使其成为一个类别时,我想在该类别中进行综合会变得令人难以置信的冒犯。当我完全删除括号时,最糟糕的噩梦发生了:它编译了。不幸的是, NSURLConnection 变得不明确,我的覆盖了真实的。它非常适合保存 userInfo,但绝对没有其他用途。
有人成功做到这一点吗?
For a project I'm working on, I need to be doing several simultaneous plist uploads with an NSURLConnection, and it'd be neat to have a userInfo property to keep track of stuff.
I have:
// header
@interface NSURLConnection ()
@property (nonatomic, retain) id userInfo;
@end
// implementation
@implementation NSURLConnection ()
@synthesize userInfo = _userInfo;
@end
When I try to compile, it says it expects an identifier in the parens. When I give it an identifier, making it a category, it becomes incredibly offended that I want to synthesize in the category. When I remove the parens entirely, the worst nightmare occurs: it compiles. Unfortunately, NSURLConnection becomes ambiguous, with mine overwriting the real one. It's great at holding userInfo, but absolutely nothing else.
Has anyone successfully done this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用替代方法,考虑从
NSURLConnection
继承您的类。这里检查 (BROKEN LINK) 添加状态到 <的简单替代解决方案code>NSURLConnection
编辑: 链接已损坏,这是一个更好的链接:
http://web.archive.org/web/20110116033842/http://www.goosoftware.co.uk/blog/adding-state-to-nsurlconnection/
(谢谢,wjl )
You could try with alternative approach by considering inheriting your a class from
NSURLConnection
.Here check the simple and alternative solution for (BROKEN LINK) adding state to
NSURLConnection
EDIT: Link broken, here's a better one:
http://web.archive.org/web/20110116033842/http://www.goosoftware.co.uk/blog/adding-state-to-nsurlconnection/
(Thanks, wjl)
我在 iPhone OS 3 的上下文中提出了这个问题。如果您的目标是 iOS 5 或更高版本,您可能希望将
+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
与块一起使用。I asked this question in the context of iPhone OS 3. If you're targeting iOS 5 or above, you probably want to use
+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
with blocks.