0
votes

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

2

2 Answers

0
votes

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) 
0
votes

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)