iOS*_*com 7 cocoa path environment-variables ios
我试过了:
path = @"~/Desktop/files/text.plist";
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)
ResultPath:〜/ Desktop/files/text.plist
path = @"$(HOME)/Desktop/files/text.plist";
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)
ResultPath:$(HOME)/Desktop/files/text.plist
path = [NSHomeDirectory() stringByAppendingString:@"/Desktop/files/text.plist"];
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)
ResultPath:/ Users/my_name/Library/Application Support/iPhone Simulator/5.1/Applications/639DC66A-7092-4ECB-9E48-59935AC1C394/Desktop/files/text.plist
编辑:第二个问题的进一步说明:就像MAC控制台中有环境变量(或宏)一样,这些也可以在代码中使用吗?如果可以使用它们,任何人都可以帮助一个例子吗?比如$ HOME_DIRECTORY或类似的东西.
Abi*_*ern 22
您可以在搜索路径中指定桌面:
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDesktopDirectory, NSUserDomainMask, YES);
NSString * desktopPath = [paths objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
这样做的好处是它不会假设用户如何配置他的Mac,如果他的桌面文件夹不在默认位置,这仍然会找到正确的位置.
| 归档时间: |
|
| 查看次数: |
10493 次 |
| 最近记录: |