在 iPhone 上查找用户文档目录的最佳方法是什么? [英] What's the best way to find the user's Documents directory on an iPhone?

查看:42
本文介绍了在 iPhone 上查找用户文档目录的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Erica Sadun 的 iPhone 开发者食谱,但遇到了一个问题.

I'm reading Erica Sadun's iPhone Developer's Cookbook, and ran into a question.

她在书中说找到用户的Documents目录的方法是用代码:

She says in the book that the way to find the user's Documents directory is with the code:

[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

但这似乎有点脆弱,并且与正常的 Mac 方式不同,后者是:

but that seems slightly brittle, and dissimiliar to the normal Mac way of doing it, which would be:

NSSearchPathForDirectoriesInDomains(NSDocumentsDirectory, NSUserDomainMask, YES);

是否有任何特别的理由来使用一个而不是另一个?

Are there any particular reasons to use one over the other?

推荐答案

Objc:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)

斯威夫特:

var paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)

您需要返回数组的第一个元素.

You'll want the first element of the returned array.

这篇关于在 iPhone 上查找用户文档目录的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆