本文介绍了NSSearchPathForDirectoriesInDomains解释混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚才一直在研究这个code,它检查文件是否存在:
的NSString *路径;
NSArray的*路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
路径= [[路径objectAtIndex:0] stringByAppendingPathComponent:@SomeDirectory];
路径= [路径stringByAppendingPathComponent:@SomeFileName];
如果([的NSFileManager defaultManager] fileExistsAtPath:路径])
{
但我有点困惑。通过以下行:
的NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
好吧,我明白的方法NSSearchPathForDirectoriesInDomains返回,这取决于你传递到该方法的参数的路径。但这个用户(谁写的code)是一味传递一个全班同学! (指的是NSDocumentDirectory,NSUserDOmainMask)。他正确地传递的唯一一件事就是BOOL YES。我检查了苹果的文档,它说的:
NSSearchPathForDirectoriesInDomains创建的目录搜索路径列表。
的NSArray * NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory目录,
NSSearchPathDomainMask domainMask,
BOOL expandTilde
);
我在苹果的文档搜索NSSearchPathDirectory和NSSearchPathDomainMask他们建议我一定要通过一些
这表明需要传递到方法是多少?有人能解释一下行吗?谢谢
解决方案
在这里Foundation框架常量阅读文档:结果
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSDocumentDirectory
这是正确的使用,因为这些都不是类,但常量!
NSSearchPathDomainMask
enum {
NSUserDomainMask = 1, //this one
NSLocalDomainMask = 2,
NSNetworkDomainMask = 4,
NSSystemDomainMask = 8,
NSAllDomainsMask = 0x0ffff,
};
typedef NSUInteger NSSearchPathDomainMask;
NSSearchPathDirectory
enum {
NSApplicationDirectory = 1,
NSDemoApplicationDirectory,
NSDeveloperApplicationDirectory,
NSAdminApplicationDirectory,
NSLibraryDirectory,
NSDeveloperDirectory,
NSUserDirectory,
NSDocumentationDirectory,
NSDocumentDirectory, // this one
NSCoreServiceDirectory,
NSAutosavedInformationDirectory = 11,
NSDesktopDirectory = 12,
NSCachesDirectory = 13,
NSApplicationSupportDirectory = 14,
NSDownloadsDirectory = 15,
NSInputMethodsDirectory = 16,
NSMoviesDirectory = 17,
NSMusicDirectory = 18,
NSPicturesDirectory = 19,
NSPrinterDescriptionDirectory = 20,
NSSharedPublicDirectory = 21,
NSPreferencePanesDirectory = 22,
NSItemReplacementDirectory = 99,
NSAllApplicationsDirectory = 100,
NSAllLibrariesDirectory = 101
};
typedef NSUInteger NSSearchPathDirectory;
这篇关于NSSearchPathForDirectoriesInDomains解释混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!