Pregunta

I'm looking to use FSPathCopyObjectAsync and I'm failing. In order to get my head around the problem I've been looking for examples of it elsewhere and although I was experimenting with the slightly dated source code from Matt Long's tutorial over on Cocoa is my Girlfriend, I then found a bit more elaborate example in a project on github, as a category on NSFileManager. Since my project is running under ARC, I tried porting it, and succeeded only at the half of it.

In its current form, the actual copying works, yet the callback method MZCopyFSPathFileOperationStatusProc is never called. That callback method happens to be the sole reason for using asynchronous copying, otherwise one might as well run a synchronous one in the background. I'm assuming the reason for the callback not being called is that some object is incorrectly released by ARC, but there could be something else going on. I am holding on to the return object of the copyItemAsyncAtPath:toPath:destName:options:statusChangeInterval:error: method, so that can't be it, right?

Who can spot the error and explain why this category isn't generating any callbacks? Is it ARC? Is it something else?

Much obliged. EP.

P.S. For redundancy reasons, here is the gist: https://gist.github.com/6f3715753896ccf6fd35

¿Fue útil?

Solución

Your delegate needs to be strongly referenced by something. NSFileManager will only hold a weak reference to it (as it should do), so if you don’t have a strong reference to it, your delegate will get released and the callbacks won’t be seen.

Have you considered using blocks for the callbacks? That would probably be preferable.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top