简体   繁体   中英

Implicit conversion of 'int' to 'NSDictionary *' is disallowed with ARC

I'm getting the error "Implicit conversion of 'int' to 'NSDictionary *' is disallowed with ARC" when I use NSFileManager - attributesOfItemAtPath.

I guess some error occurred while I'm try to knowing size of file. Is there any method to solving this problem?

    #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;
}

Thank you

Other methods you're using: moveItemAtPath , contentsEqualAtPath , copyItemAtPath , fileExistsAtPath - they all return a BOOL . But attributesOfItemAtPath returns NSDictionary and you can't compare NSDictionary to BOOL ( NO )

try instead

((attr = [fm attributesOfItemAtPath:@"newfile2" error:nil]) == nil)

You compare a reference to an instance of a dictionary with the integral type NO , what is an integer. Likely you want to check against nil . Moreover you should use parenthesis on the left side, otherwise the compiler tries to assing the result of […]==NO to attribute:

if( (attr = [fm attributesOfItemAtPath:@"newfile2" error:nil]) == nil) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM