在 ARC 中获取 FSPathCopyObjectAsync 的回调
我正在寻找使用 FSPathCopyObjectAsync
但失败了。为了解决这个问题,我一直在其他地方寻找它的示例,尽管我正在尝试 Matt Long 关于 Cocoa 的教程是我的女朋友,然后我在 github 上的项目,作为 NSFileManager 上的类别
。由于我的项目是在ARC下运行的,所以我尝试移植它,但只成功了一半。
在其当前形式中,实际复制有效,但回调方法MZCopyFSPathFileOperationStatusProc
是从来没有打电话过。该回调方法恰好是使用异步复制的唯一原因,否则最好在后台运行同步复制。我假设回调未被调用的原因是 ARC 错误地释放了某个对象,但可能还有其他原因。我保留了 copyItemAsyncAtPath:toPath:destName:options:statusChangeInterval:error:
方法的返回对象,所以不可能是这样,对吗?
谁可以发现错误并解释为什么此类别没有生成任何回调?是ARC吗?难道是别的什么?
多谢。 EP。
PS出于冗余原因,要点如下: https://gist.github.com/6f3715753896ccf6fd35
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代表需要被某些东西强烈引用。 NSFileManager 只会保留对它的弱引用(正如它应该做的那样),因此如果您没有对它的强引用,您的委托将被释放并且回调将不会被看到。
您是否考虑过使用回调块?这可能会更好。
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.