NSFileManager: removing item

前端 未结 3 1922
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 23:36

The problem is removing an item that´s been written using writeToFile: method, I cannot seem to remove it. I tried NSFileManager but I guess these are two different

相关标签:
3条回答
  • 2021-01-29 00:21

    And the "for some reason": your "URL" is just a path, it's not a valid filesystem URL. For that, you would need to prepend file:// before the actual path, or even better, use [NSURL fileURLWithPath:].

    0 讨论(0)
  • 2021-01-29 00:21

    In this place

    result = [fileManager removeItemAtURL:destinationURL error:&removeError];
    NSLog(@"ERROR REMOVING OBJECT: %@",removeError);
    

    you log and do not check the result value. Is it really NO? You should check return value first, and then if it is NO, check the removeError.

    And also I prefer to write

    NSError * removeError = nil;
    

    when declarate it. May be removeError object contains some old information.

    0 讨论(0)
  • 2021-01-29 00:23

    If your file is present at that path you can try this:

        [[NSFileManager defaultManager] removeItemAtPath:[destinationURL path] error:&error];
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题