iOS Documents Directory 每次都需要构建吗?

Does the iOS Documents Directory need to be constructed every time?

我正在编写一个执行大量文件操作的 iOS 应用程序。每次都执行 [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 以获得 Documents 目录的根目录是很乏味的。

有必要吗?

我能以某种方式将它存储在某种全局变量中吗?

该值在应用程序的单个 运行 期间永远不会改变,所以是的,在应用程序启动时获取一次并在整个应用程序中重复使用该值是安全的。

但永远不要保留该值。下次应用 运行s.

时可能会有所不同