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

问题描述

我在阅读Erica Sadun的iPhone开发人员食谱,遇到了一个问题。



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

  [NSHomeDirectory()stringByAppendingPathComponent:@Documents]; 

但是这看起来有点脆弱,并且对正常的Mac方式不太熟悉,

  NSSearchPathForDirectoriesInDomains(NSDocumentsDirectory,NSUserDomainMask,YES); 

有什么特别的理由使用另一个吗?



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

Swift:

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

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


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

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

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

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)

Swift:

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

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

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

08-21 15:56