NSFileManager refuses to acknowledge existence of file
Hi
I have saved a dictionary as a plist to my documents directory using writeToFile:atomically: and can see that it exists in the simulator in Finder and on the device as well.
I then do this to try and read the file back in again, but the exists BOOL is never YES.
Code:
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"items.plist"];
if (path) {
NSLog(@"%@",path);
}
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if (exists)
//do stuff with it...
How can i get NSFileManager to recognize my plist exists?
At the beginning of the line, the boolean is NO, because that's how booleans begin life. At the end of the line, it will change to whatever the result of the operation is. Do you know which moment in time your tooltip refers to?
When i put a breakpoint on the if(exists) it highlights the first line (1) in blue then moves on the second position.... I'll assume this now means that it is going into the first branch, completing the statement, and then ending the if? If so, ignore my previous problem.
Honestly, why are you relying on a tool that you don't know how to use? Don't feel bad about not knowing how to use it - I don't either - but at least recognize that you don't know what you are doing and thus be wary of any conclusions you draw from the use of said tool.
Logging is very easy.
Code:
if (exists)
{
NSLog(@"File exists");
}
else
{
NSLog(@"File does not exist");
}
I apologize for the confusion, the log shows that the if is valid and thus the file exists. My problem must now be in whether applicationDidEnterForeground is called when the application launches, and not just resumes from suspension.
Just want to add: If you're seeing strange behavior in the debugger, make sure you're debugging the DEBUG build, not the RELEASE. A normal RELEASE build will optimize away some amount of code, leaving you with machine code that doesn't really correspond 1:1 with your source code, which makes it very confusing when stepping through the source in the debugger.
I apologize for the confusion, the log shows that the if is valid and thus the file exists. My problem must now be in whether applicationDidEnterForeground is called when the application launches, and not just resumes from suspension.
You probably meant 'applicationWillEnterForeground' (there is no 'applicationDidEnterForeground' notification), and you can review which notifications are called when in the protocol doc, here: UIApplicationDelegate Protocol Reference.