I have tried:
path = @"~/Desktop/files/text.plist";
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
ResultPath: ~/Desktop/files/text.plist
path = @"$(HOME)/Desktop/files/text.plist";
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
ResultPath: $(HOME)/Desktop/files/text.plist
path = [NSHomeDirectory() stringByAppendingString:@"/Desktop/files/text.plist"];
NSDictionary *aDict = [NSDictionary dictionaryWithContentsOfFile:path];
ResultPath: /Users/my_name/Library/Application Support/iPhone Simulator/5.1/Applications/639DC66A-7092-4ECB-9E48-59935AC1C394/Desktop/files/text.plist
EDIT: Further explanation on 2nd question: Just like there are environment variables (or Macros) in the MAC console, can these also be used within the code? If they can be used, can any one help with an example? like $HOME_DIRECTORY or something like that.
You can specify the desktop in the search path:
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDesktopDirectory, NSUserDomainMask, YES);
NSString * desktopPath = [paths objectAtIndex:0];
The advantage of doing it this way is that it makes no assumptions about how the user has configured his Mac, If his desktop folder isn't in the default location, this will still find the correct one.
This should work:
NSString *pathToDesktop = [NSString stringWithFormat:@"/Users/%@/Desktop/text.txt", NSUserName()];
I use this statement, it assumes that the Desktop folder is in the usual location.
[NSURL fileURLWithPath:[NSHomeDirectory()stringByAppendingPathComponent:@"Desktop"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With