Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. - (void)applicationDidEnterBackground:(UIApplication *)application
  2. {
  3.     NSString *path = [self filePath:@"test.txt"];
  4.     if ([[NSFileManager defaultManager] fileExistsAtPath:path])
  5.     {
  6.         NSLog(@"file exist");
  7.     }
  8.     else
  9.     {
  10.         NSLog(@"create file");
  11.         MyObject *myObj = [[MyObject alloc] init];
  12.         myObj.name = @"peter";
  13.         myObj.age = 18;
  14.         myObj.color = @"blue";
  15.     NSMutableData *data = [[NSMutableData alloc] init];
  16.         NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
  17.         [archiver encodeObject:myObj forKey:@"MY_OBJ"];
  18.         [archiver finishEncoding];
  19.         [data writeToFile:path atomically:YES];
  20.     }
  21. }