views:

81

answers:

2

Hi, and again my array of arrays ... I try to improve my app performance by buffering arrays on file for later reuse.

I have an NSMutableArray that contains about 30 NSMutableArrays with NSNumber, NSDate and NSString Objects.

I try to write the file using this call:

bool result = [myArray writeToFile:[fileMethods 
                                    getFullPath:[NSString 
                                                 stringWithFormat:@"iEts%@.arr", 
                                                 [aDate shortDateString]]] 
                       atomically:NO];

=> result = FALSE.

The Path method is:

+ (NSString *) getFullPath:(NSString *)forFileName {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:forFileName];
}

and the aDate call returns a shortDateString with ddMMyy.

The NSLog

NSLog(@"%@", [fileMethods getFullPath:[NSString stringWithFormat:@"iEts%@.arr", 
                                                [aDate shortDateString]]]);

on the path generation returns:

/Users/me/Library/Application Support/iPhone Simulator/User/Applications/86729620-EC1D-4C10-A799-0C638BB27933/Documents/iEts010510.arr

FURTHER:

  • It must have something to do with the Array of Arrays, since I also write 3 further simple arrays (containing NSStrings) that all succeed.
  • The Array of Arrays gets generated using the addObject method

Any ideas what could cause the trouble?

+2  A: 

AFAIK the write to file uses object archiving hence some objects in your array of arrays can't be archived.

Eimantas
Property list, not object archiving. Same general effect, though.
Paul Lynch
hmm, I followed your lead and started test writing the sub-arrays. It seems that those with empty NSStrings fail to write. Adding a single space character doesn't help either ....
iFloh
don't get it. neither NSNumber, NSDate, nor NSString are reported as troublemakers. Filling my empty strings with some text also doesn't change anything .... weird. In my subarray enumeration it writes the subarray when 1 object was attached, from the second object onwards it fails ...
iFloh
+1  A: 

Have you got any NSNulls in your arrays anywhere? I don't think they count as plist objects and so would cause the write to fail.

JeremyP
I had empty string in the array, but when I test filled them the array store still failed - situation unchanged
iFloh