daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Apr 17th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (void) saveData:(NSMutableArray*)theArray {
  2.    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  3.   // NSMutableArray *arr = ... ; // set value
  4.    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:theArray];
  5.    [defaults setObject:data forKey:[NSString stringWithFormat:@"myKey"]];
  6.    NSLog(@"Saved stuff to user defaults");
  7.    
  8. }
  9.  
  10. - (NSMutableArray*) loadData {
  11.    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  12.    NSData *data = [defaults objectForKey:[NSString stringWithFormat:@"myKey"]];
  13.    NSMutableArray *aArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  14.    //notes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  15.    NSLog(@"Loading stuff from user defaults");
  16.    return aArray;
  17. }
  18. didär metoderna används för att spara/ladda data
  19. - (void) encodeWithCoder:(NSCoder *)encoder {
  20.    //Encoding stuff
  21.    
  22.    self = [super init];
  23.    if (self != nil) {
  24.        [encoder encodeObject:self.noteContent forKey:@"noteContent"];
  25.        [encoder encodeObject:self.noteCreatedDate forKey:@"noteCreatedDate"];
  26.        [encoder encodeObject:self.title forKey:@"title"];
  27.    }
  28. }
  29.  
  30. -(id)initWithCoder:(NSCoder *)decoder
  31. {
  32.    //Decodes stuff
  33.    self.noteContent = [decoder decodeObjectForKey:@"noteContent"];
  34.    self.noteCreatedDate = [decoder decodeObjectForKey:@"noteCreadetDate"];
  35.    self.title = [decoder decodeObjectForKey:@"title"];
  36.    return self;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top