当我使用NSFileManager - attributesOfItemAtPath时,我收到错误“使用ARC禁止将'int'隐式转换为'NSDictionary *'。
我想在我试图了解文件大小时发生了一些错误。 有没有办法解决这个问题?
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *fName = @"testfile";
NSFileManager *fm;
NSDictionary *attr;
fm = [NSFileManager defaultManager];
if([fm fileExistsAtPath:fName]==NO){
NSLog(@"File doesnt exist!");
return 1;
}
if([fm copyItemAtPath:fName toPath:@"newfile" error:nil]==0){
NSLog(@"Files copy Failed!");
return 2;
}
if([fm contentsEqualAtPath:@"newfile" andPath:@"newfile2"] == NO){
NSLog(@"File arent equal");
return 3;
}
if([fm moveItemAtPath:@"newfile" toPath:@"newfile2" error:nil] == NO){
NSLog(@"file rename failed");
return 4;
}
//Here
if((attr = [fm attributesOfItemAtPath:@"newfile2" error:nil] == NO)){
return 5;
}
}
return 0;
}
谢谢
答案 0 :(得分:0)
您正在使用的其他方法:moveItemAtPath
,contentsEqualAtPath
,copyItemAtPath
,fileExistsAtPath
- 它们都返回BOOL
。但是attributesOfItemAtPath
会返回NSDictionary
,您无法将NSDictionary
与BOOL
进行比较(NO
)
尝试改为
((attr = [fm attributesOfItemAtPath:@"newfile2" error:nil]) == nil)
答案 1 :(得分:0)
将对字典实例的引用与整数类型NO
进行比较,什么是整数。您可能想要查看nil
。此外,您应该在左侧使用括号,否则编译器会尝试将[…]==NO
的结果赋予属性:
if( (attr = [fm attributesOfItemAtPath:@"newfile2" error:nil]) == nil)