fileManager:shouldProceedAfterError:copyingItemAtPath:toPath:

In working with NSFileManager I’m not clear how to implement the following delegate.

fileManager:shouldProceedAfterError:copyingItemAtPath:toPath:

Do I just create a handler like:


on copyFile_sourcePath_destinationPath_(theSourcePath, theDestinationPath)
        return current application's NSFileManager's defaultManager()'s copyItemAtPath_toPath_error_(theSourcePath,             theDestinationPath, missing value)
end copyFile_sourcePath_destinationPath_withAttributes_attributes_

on fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_()
    return true
end fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_

Confused. --Andrew

To use the delegate methods, you should use alloc()'s init() rather than defaultManager(), and set the file manager instance’s delegate to your script class using setDelegate_.

Okay, assuming I do that, then what? Was I on the right track? Can you show me some quick example code of what the delegate would look like? I would greatly appreciate it. Thanks. --Andrew

Your delegate code is fine, if pointless. What do you want to do, actually?

Hm. Pointless? More than anything I’m trying to understand delegates, but my hope was to make sure my code executes without crashing if it runs into an error like copying a file that already exists at the destination. Is it pointless because I should be managing the errors myself with code? Is it just my implementation that is pointless or are NSFIleManager delegates pointless and ready to be deprecated?

I’ve read your book, but I learn through doing more than reading. I’ve wrapped my brain around much of ASOC in the past month or so, but I struggle when it comes to some delegate issues. Any insight will not be wasted. Thanks. --Andrew

Pointless in the sense that a delegate that always returns true like your sample is the same as having no delegate.

You can also get the result of your move/copy/whatever and decide on that; the delegate just gives you a different way to structure your code.

I don’t think that’s true in this case – the docs say that the file manager assumes “no” if the delegate method is not implemented.

Ric

and you’re gonna miss a variable in your handler:

on copyFile_sourcePath_destinationPath_(theSourcePath, theDestinationPath)

you have three _ and only 2 variables. :slight_smile:

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

You are right, of course. Let me try again:

It’s pointless in the sense that (a) it does nothing itself, and (b) it tells the copy/move method that all went well regardless of what actually happened, so masking any problems.