Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3871504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:49:49+00:00 2026-05-19T21:49:49+00:00

I’m a (kind of) newbie XCode programmer (well, I would say not so newbie

  • 0

I’m a (kind of) newbie XCode programmer (well, I would say not so newbie nowadays…) and “my pet issue” is: “I’m having trouble saving local files onto my real iPad, compared to saving them with the simulator”.

Well to be honest, I have no problem whatsoever SAVING local files, but retrieving them. Why? Because on the simulator my local files seem to persist between compilation sessions, but on the real device, every time the application gets launched (not only after being uploaded from Xcode, but normally launched), data inside the “Documents” directory seems to disappear… So the final user would not be able to store needed historical data between sessions.

Is it a perception of mine? Is it normal behaviour?

The code I use to save this “persistent” data is this one:

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDir = [paths objectAtIndex:0];
NSString *finalPath=[NSString stringWithFormat:@"%@/%@", documentsDir, path];
NSLog(@"Course.m: updatePersistentObject (to disk): final file = %@",finalPath);
[NSKeyedArchiver archiveRootObject:newObject toFile:finalPath];

‘path’ variable being @”.HistoricalTestResults”;

The code I use to retrieve data (wheather at boot time, or at runtime) is this one:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@" historical data: Documents paths = %@", paths);      

NSString * docsDir = [paths objectAtIndex:0];
NSLog(@"Course.m: loadHistoricalResultsData: docsDir vale [%@]", docsDir);

NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];
NSLog(@"Course.m: loadHistoricalResultsData: tmpPath vale [%@]", tmpPath);

NSFileManager *localFileManager = [[NSFileManager alloc] init];

// create directory if it doesn't exist, don't do anything if it exists... (?)
[localFileManager createDirectoryAtPath:tmpPath withIntermediateDirectories:YES attributes:nil error:nil];
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tmpPath];

NSString *file;    

while (file = [ dirEnum nextObject])
{
    NSLog(@"Historical Data Folder: %@", file);
    if ( [[file pathExtension] compare:@"dat"] == NSOrderedSame  )
    {
        NSString *filePath = [NSString stringWithFormat:@"%@/%@", tmpPath, file];
        NSLog(@"Course.m: loadHistoricalResultsData: filePath vale [%@]", filePath);
        mHistoricalTestList=[[NSKeyedUnarchiver unarchiveObjectWithFile:filePath] retain];
    }
}
[localFileManager release];

My exact problem is that while on the simulator, AT BOOT TIME, if I put a trace on the “while” code line, I can see how the enumerator gets some value, and I can iterate among the found files.
On the other hand, when using my iPad, the same breakpoint yields a “nil” pointer when obtaining the enumerator.

As I said, at the beginning of a clean program session, this is normal, so then I need to generate some storable results inside my program memory to store them onto disk.
I do it, and then I write them (both inside the simulator and the iPad). Then I can even re-retrieve this data (from disk) and it seems to still exist inside the Documents folder (both onto the iPad and the simulator).

But then, if I close/kill the program, this data seems to be lost onto the real iPad, and to persist in the simulator.

With this behaviour, my only deduction is “Real iPad programs cannot store persistent data onto their Documents directory”. Am I right? (Of course not, because I’ve seen it work on some other programs).
So I have the feeling I’m doing something wrong, and after wasting TONS of time trying to find it, I’m now asking for advice on stackoverflow…

Every piece of help/insight/hint will be more than welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:49:49+00:00Added an answer on May 19, 2026 at 9:49 pm

    I’m happy! I was able to solve my own mess (!!?).

    I’ve discovered that, when I originally copied my 2 code snippets, specially the “read part”, I didn’t copy it literally as it appears on my actual code, I just adapted some variable names and extra stuff that wasn’t important here. (Typical situation)

    I even did some more things than “removing some unrelated code pieces”, (and here comes the important part), as I reordered some of them. And one of the parts I reordered was this one (which didn’t work):

    NSFileManager *localFileManager = [[NSFileManager alloc] init];
    
    NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];
    
    NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tmpPath];
    // create directory if it doesn't exist, don't do anything if it exists... (?)
    [localFileManager createDirectoryAtPath:tmpPath withIntermediateDirectories:YES attributes:nil error:nil];
    

    which I changed (when posting here), onto this other part (which works):

    NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];
    
    NSFileManager *localFileManager = [[NSFileManager alloc] init];    
    // create directory if it doesn't exist, don't do anything if it exists... (?)
    [localFileManager createDirectoryAtPath:tmpPath withIntermediateDirectories:YES attributes:nil error:nil];
    NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tmpPath];
    

    There’s proably some logic behind this, as “why the first part does work on the emulator, but doesn’t on the real device”. It seems that “createDirectoryAtPath” is somewhat “resetting” some internal stuff, or maybe asking for an enumerator without having created a directory doesn’t make sense…

    Whatever the case is, I think my experience is worth enough to keep it here posted for someone who might be in my situation in the future!

    Greetings again!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.