Sending 'NSProgress *__strong *' to parameter of incompatible type 'void (^ _Nullable)(NSProgress *
来源:互联网 发布:建筑三维计算软件 编辑:程序博客网 时间:2024/05/24 15:39
使用AFNetWorking 3.0下载文件,网络上给出了很多示例代码,在XCode 7.2上运行,直接报错。
原始代码:
NSURLSessionDownloadTask *downTask = [manager downloadTaskWithRequest:request progress:&progressTemp destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
//告诉服务器下载的文本保存的位置在那里
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSLog(@"file = %@",targetPath);
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"response = %@,filePath = %@",response,filePath);
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[resourcePath path] isDirectory:NULL]) {
[fileManager removeItemAtURL:resourcePath error:NULL];
}
BOOL seccess =[fileManager moveItemAtURL:filePath toURL:resourcePath error:NULL];
if (seccess)
{}
}];
报错信息:
Sending 'NSProgress *__strong *' to parameter of incompatible type'void (^ _Nullable)(NSProgress * _Nonnull __strong)'
字面意思是传递的参数类型不符,
查看AFNetWorking源文件,找到对应的SDK,
- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
destination:(NSURL * (^)(NSURL *targetPath,NSURLResponse *response))destination
completionHandler:(void (^)(NSURLResponse *response,NSURL *filePath, NSError *error))completionHandler
确定progress后面的参数是一个入参为NSProgress的block,而我们传递进去的是一个指针,类型不匹配,所以报错。简单修改后的代码如下:
NSURLSessionDownloadTask *downTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){NSLog(@"progress is %@", downloadProgress);} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {}
应该专门定义一个block来处理下载进度。
- Sending 'NSProgress *__strong *' to parameter of incompatible type 'void (^ _Nullable)(NSProgress *
- const 定义警告 Sending 'const NSString *__strong' to parameter of type 'NSString * _Nullable'...
- Sending 'ViewController *const __strong' to parameter of incompatible type 'id<***Delegate>'
- Sending 'ViewController *const __strong' to parameter of incompatible type 'id<***Delegate>'
- Sending 'xxx *const __strong' to parameter of incompatible type 'id<aDelegate>'
- Sending 'AppDelegate *const __strong' to parameter of incompatible type 'id<******Delegate>'
- NSProgress
- NSProgress
- Sending 'ViewController' to Parameter of Incompatible Type 'id<xxxDelegate>'
- Initializing 'Object' *__strong' with an expression of incompatible type 'id <Object> _Nullable
- Sending 'ccColor4B' (aka 'struct _ccColor4B') to parameter of incompatible type 'CIColor *'
- [cocos2d]Sending 'ccColor4B' (aka 'struct _ccColor4B') to parameter of incompatible type 解决办法
- Sending 'ccColor4B' (aka 'struct _ccColor4B') to parameter of incompatible type 'CIColor *'错误
- 警告解决办法sending 'viewcontroller *' to parameter of incompatible type 'id UMSocialUIDelegate
- 报错原因:Incompatible pointer types sending 'UIImage *' to parameter of type 'NSString * _Nonnull'
- Sending 'ShareView *const _strong' to parameter of incompatible type 'id<UIAlertViewDelegate>'
- IOS NSProgress
- Assigning to ‘APPDelegate’ from incompatible type ‘id<UIApplicationDelegate> _Nullable’
- iOS 页面自动布局-NSLayoutConstraint简介
- 理解JVM工作原理总结
- iOS----网络开发之第三方库AFNetworking
- 通过一个大型项目来学习分布式算法(6)
- 颜色的类别 可以直接写 #333333 一句代码就能实现
- Sending 'NSProgress *__strong *' to parameter of incompatible type 'void (^ _Nullable)(NSProgress *
- C#程序设计教程编程题(一)
- 电话拨号
- JAVA排序算法---归并排序
- QT 从尾部截取字符串(从路径中截取文件名)
- Github使用学习笔记(一)
- Android Thread子线程和主线程的UI交互
- 技术点整理
- 不用递归,写出快速求幂的程序