Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-12-2010, 02:36 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default 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?

Thanks
Joe
joec is offline   Reply With Quote
Old 10-12-2010, 02:53 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Is the path log correct when you do that?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 02:58 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Is the path log correct when you do that?
Yeah, thats what i dont understand. I just pasted the output of the path log into a terminal and vim opened it right up.
joec is offline   Reply With Quote
Old 10-12-2010, 03:01 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You've logged the boolean?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:02 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

Having a breakpoint on it resolves to NO, then the if always skips over.
joec is offline   Reply With Quote
Old 10-12-2010, 03:05 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Humor me and log it.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:08 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

EXC_BAD_ACCESS when i do NSLog(exists)
joec is offline   Reply With Quote
Old 10-12-2010, 03:09 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

That doesn't make any sense. Show your log statement.

Edit: Duh. it's right there.

That doesn't work.

Code:
NSLog(@"exists is: %@", (exists) ? @"YES" : @"NO");
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:12 PM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

exists is YES
joec is offline   Reply With Quote
Old 10-12-2010, 03:12 PM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

So the problem is not in this code.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:14 PM   #11 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

But the if is always skipped, and the debugger tooltip always says NO
joec is offline   Reply With Quote
Old 10-12-2010, 03:16 PM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

How are you verifying that the if is skipped?

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?

This is why I log.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:21 PM   #13 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

This is my if
Code:
	if (exists) {
		itemsDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:path]; //1
		[itemsDictionary retain];
		
	}else{
		itemsDictionary = [NSMutableDictionary dictionaryWithCapacity:30];
		[itemsDictionary retain]; //2
	}
Stepping through, it goes from position 1 to 2...
joec is offline   Reply With Quote
Old 10-12-2010, 03:23 PM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

It can't go from 1 to 2 because they are in different branches.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:28 PM   #15 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

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.
joec is offline   Reply With Quote
Old 10-12-2010, 03:31 PM   #16 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

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");
}
Done. No confusion.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 10-12-2010, 03:40 PM   #17 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

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.
joec is offline   Reply With Quote
Old 10-12-2010, 03:41 PM   #18 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

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.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 10-12-2010, 03:45 PM   #19 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 65
joec is on a distinguished road
Default

D'Oh I was debugging the release build. I should not code at this late hour!
joec is offline   Reply With Quote
Old 10-12-2010, 03:46 PM   #20 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by joec View Post
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.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Reply

Bookmarks

Tags
nsfilemanager, persistent data, plist

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 351
8 members and 343 guests
Desert Diva, dre, freewind, hain, HemiMG, lendo, mottdog, oceanlablight
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0