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?
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)
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.
精彩评论