gpt4 book ai didi

ios - 为什么 Apple 在使用 NSFileManagerDelegate 时建议使用自己的 NSFileManager?

转载 作者:行者123 更新时间:2023-11-29 01:52:11 25 4
gpt4 key购买 nike

defaultManager 的苹果文档中,他们说:

This method always returns the same file manager object. If you plan to use a delegate with the file manager to receive notifications about the completion of file-based operations, you should create a new instance of NSFileManager (using the init method) rather than using the shared object.

我只是想知道为什么当您使用文件管理器的委托(delegate)时他们建议使用 NFileManager 的新实例?如果我使用共享文件管理器来执行此操作有什么问题?

我唯一能看到的就是你的delegate对象会收到很多你不想知道的通知,是不是还有什么?

最佳答案

你的最后一段就差不多了。如果您在共享文件管理器上设置委托(delegate),您的委托(delegate)最终会被调用的次数超出您的预期。通过创建 NSFileManager 的特定实例并设置该实例的 delegate,您就会知道仅针对文件管理器的特定用途调用委托(delegate)方法,而不是所有默认使用。

请记住,默认文件管理器实例可以被比您自己的代码更多的人使用。许多其他库和框架也将使用它。

关于ios - 为什么 Apple 在使用 NSFileManagerDelegate 时建议使用自己的 NSFileManager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31282239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com