Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can store your NSMutableArray to NSUserDefault by archiving it to NSData and than retrieving it by Unarchiving it back to NSMutableArray. </p> <pre><code>-(NSData*) getArchievedDataFromArray:(NSMutableArray*)arr { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:arr]; return data; } -(NSMutableArray*) getArrayFromArchievedData:(NSData*)data { NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:data]; return arr; } </code></pre> <p>For saving array to NSUserDefault :</p> <pre><code> [[NSUserDefaults standardUserDefaults] setObject:[self getArchievedDataFromArray: yourArray] forKey:@"YourKey"]; [[NSUserDefaults standardUserDefaults] synchronize]; </code></pre> <p>For retrieving array back from NSUserDefault :</p> <pre><code>NSMutableArray *yourArray = [self getArrayFromArchievedData:[[NSUserDefaults standardUserDefaults]objectForKey:@"YourKey"]]; </code></pre> <p>Also you can save Array in form of NSData to a file in NSDocumentDirectory or NSCachesDirectory. Hope this helps....</p> <p>Edited: <strong>An UIImage+NSCoding category</strong> </p> <p>.h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface UIImage (NSCoding) - (id) initWithCoderForArchiver:(NSCoder *)decoder; - (void) encodeWithCoderForArchiver:(NSCoder *)encoder ; @end </code></pre> <p>.m file</p> <pre><code>#import "UIImage+NSCoding.h" #import &lt;objc/runtime.h&gt; #define kEncodingKey @"UIImage" @implementation UIImage (NSCoding) + (void) load { @autoreleasepool { if (![UIImage conformsToProtocol:@protocol(NSCoding)]) { Class class = [UIImage class]; if (!class_addMethod( class, @selector(initWithCoder:), class_getMethodImplementation(class, @selector(initWithCoderForArchiver:)), protocol_getMethodDescription(@protocol(NSCoding), @selector(initWithCoder:), YES, YES).types )) { NSLog(@"Critical Error - [UIImage initWithCoder:] not defined."); } if (!class_addMethod( class, @selector(encodeWithCoder:), class_getMethodImplementation(class, @selector(encodeWithCoderForArchiver:)), protocol_getMethodDescription(@protocol(NSCoding), @selector(encodeWithCoder:), YES, YES).types )) { NSLog(@"Critical Error - [UIImage encodeWithCoder:] not defined."); } } } } - (id) initWithCoderForArchiver:(NSCoder *)decoder { if (self = [super init]) { NSData *data = [decoder decodeObjectForKey:kEncodingKey]; self = [self initWithData:data]; } return self; } - (void) encodeWithCoderForArchiver:(NSCoder *)encoder { NSData *data = UIImagePNGRepresentation(self); [encoder encodeObject:data forKey:kEncodingKey]; } @end </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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