Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving in NSDocumentDirectory or NSCachesDirectory
    primarykey
    data
    text
    <p>Have tried storing my <code>NSMutableArray</code>'s object to <code>NSUserDefaults</code> but, no luck. My <code>NSMutableArray</code> contains this log right here: </p> <pre><code>`ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=92A7A24F-D54B-496E-B250-542BBE37BE8C&amp;ext=JPG` </code></pre> <p>I know that its a <code>ALAsset object</code>, in the <code>AGImagePickerController</code> it is compared as NSDictionary, so what I needed to do is save the NSDictionary or the Array I used to where I store my <code>ALAsset object</code> then save it in either in <code>NSDocu</code> or <code>NSCaches</code> as a file then retrieve it again (This was my idea).</p> <p>But the problem is,Though I tried this code but not working, and doesn't display anything in <code>NSDocu</code> or <code>NSCache</code> Directories.</p> <p><strong>First try</strong> (<code>info</code> is the one that contains <code>ALAsset object</code>):</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] &gt; 0) ? [paths objectAtIndex:0] : nil; NSString *filePath = [basePath stringByAppendingPathComponent:@"filename.plist"]; NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:filePath]; NSString *error; NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&amp;error]; if(plistData) { [info writeToFile:filePath atomically:YES]; } else { NSLog(error); } </code></pre> <p><strong>Second try</strong>:</p> <pre><code>- (NSString *)createEditableCopyOfFileIfNeeded:(NSString *)_filename { // First, test for existence. BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *writableFilePath = [documentsDirectory stringByAppendingPathComponent: _filename ]; success = [fileManager fileExistsAtPath:writableFilePath]; if (success) return writableFilePath; // The writable file does not exist, so copy the default to the appropriate location. NSString *defaultFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: _filename ]; success = [fileManager copyItemAtPath:defaultFilePath toPath:writableFilePath error:&amp;error]; if (!success) { NSLog([error localizedDescription]); NSAssert1(0, @"Failed to create writable file with message '%@'.", [error localizedDescription]); } return writableFilePath; } </code></pre> <p>Save it this way:</p> <pre><code> NSString *writableFilePath = [self createEditableCopyOfFileIfNeeded:[NSString stringWithString:@"hiscores"]]; if (![info writeToFile:writableFilePath atomically:YES]){ NSLog(@"WRITE ERROR"); } </code></pre> <p><strong>Third try</strong>:</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:??????]; [info writeToFile:filePath atomically:YES]; </code></pre> <p><strong>Fourth try</strong>(Unsure of because of its modifying in the appbundle): <a href="https://stackoverflow.com/a/6311129/1302274">https://stackoverflow.com/a/6311129/1302274</a></p> <p>Is there other way? Hope someone would guide me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload