block注意执行时,所在的线程
2016-04-15 11:40
183 查看
block作为回调使用时,需要注意block所在的线程;
比如,使用AFNetworking接口时,有些block 不在主线程里:
/**
Creates and runs an `NSURLSessionDataTask` with a `GET` request.
@param URLString The URL string used to create the request URL.
@param parameters The parameters to be encoded according to the client request serializer.
@param downloadProgress A block object to be executed when the download progress is updated. <span style="color:#ff0000;background-color: rgb(255, 255, 102);">Note this block is called on the session queue, not the main queue.</span>
@param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
@param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
@see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
*/
- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
parameters:(nullable id)parameters
progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
比如,使用AFNetworking接口时,有些block 不在主线程里:
/**
Creates and runs an `NSURLSessionDataTask` with a `GET` request.
@param URLString The URL string used to create the request URL.
@param parameters The parameters to be encoded according to the client request serializer.
@param downloadProgress A block object to be executed when the download progress is updated. <span style="color:#ff0000;background-color: rgb(255, 255, 102);">Note this block is called on the session queue, not the main queue.</span>
@param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
@param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
@see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
*/
- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
parameters:(nullable id)parameters
progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
相关文章推荐
- 动态链接(dynamic link)与静态链接(static link)
- hdu3294回文串
- 获取屏幕辅助类
- Linux查看系统配置常用命令
- 划分树
- Windows7-32位系统下R语言链接mySQL数据库步骤
- Centos 6.5 2.6内核升级到4.5.1内核
- springmvc实现文件上传下载
- Android 开发实战经验总结
- AngularJs多重视图和路由的使用
- Canvas使用笔记
- [转] 坚持27天你的英语水平犹如美国人
- myEclipse中设置代码区的背景颜色
- 荀策网络:“互联网+”还是“+互联网”?
- LeetCode *** 78. Subsets
- 64、JS解析JSON字符串
- FB_TYPE_*部分注解
- redisTemplate 操作及相关配置学习笔记
- CTF之路1——virtualbox安装教程
- 我的2016年决心书