ASIHTTPRequest with block
2013-06-03 22:03
148 查看
As of v1.8, we can do the same thing using blocks, on platforms that support them:
Note the use of the __block qualifier when we declare the request, this is important! It tells the block not to retain the request, which is important in preventing a retain-cycle, since the request
will always retain the block.
blocks
2 Blocks
Programming Topics - Object and Block Variables
- (IBAction)grabURLInBackground:(id)sender { NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"]; __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setCompletionBlock:^{ // Use when fetching text data NSString *responseString = [request responseString]; // Use when fetching binary data NSData *responseData = [request responseData]; }]; [request setFailedBlock:^{ NSError *error = [request error]; }]; [request startAsynchronous]; }
Note the use of the __block qualifier when we declare the request, this is important! It tells the block not to retain the request, which is important in preventing a retain-cycle, since the request
will always retain the block.
参考资料
1 http://allseeing-i.com/ASIHTTPRequest/How-to-use - Usingblocks
2 Blocks
Programming Topics - Object and Block Variables
相关文章推荐
- ASIHTTPRequest with Cookie
- 几篇网文利用Block回调,ASIHTTPRequest 实现登录验证
- ASIHttpRequest "_UTTypeCopyPreferredTagWithClass", referenced from:
- ASIHttpRequest parses URL with spaces
- How to deal with "Incorrect NSStringEncoding value 0×0000 Error with ASIHTTPRequest" problem?
- 由ASIHttpRequest里的block引发的思考
- ASIHttpRequest block在ARC下使用时出错circle retain的问题及解决方法
- asihttprequest在arc项目里用了block出现的问题
- How to upload images with text using iPhone SDK using ASIHttpRequest ?
- 用ASIHTTPRequest 的block方式请求数据
- ASIHttpRequest中Block代码块的使用和注意事项
- ASIHTTPRequest with SSL
- ASIHTTPRequest获取精准进度百分比 使用Block回调
- ASIHttpRequest "_UTTypeCopyPreferredTagWithClass", referenced from:
- ARC ASIHttpRequest block时出错circle retain的问题及解决方法
- ASIHTTPRequest with Https
- ASIHTTPRequest 详解< 转>
- AFNetworking、MKNetworkKit和ASIHTTPRequest对比
- ASIHTTPRequest 详解
- ASIHTTPRequest 封装