title: How to assign a unique ID to object created locally
body: <p>I am planning to use CloudKit later on, which as I understand can assign unique ObjectIDs in the cloud automatically, but for editing and update purposes I would like to create those unique IDs on my own and set an attribute in CoreData.</p>
  
  <p>Can you please suggest the right approach to creating a unique ObjectID in my code?</p>
  
  <p>I have so far this code:</p>
  
  <pre><code>+ (CoreDataStatus)saveNewItem:(NSString *)text date:(NSDate *)date priority:(NSUInteger)priority
  {
      NSManagedObjectContext *context = [self getContext];
      AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
      __block NSError *error;
  
      [context performBlockAndWait:^{
          Task *newTask = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:context];
          newTask.due = date;
          newTask.text = text;
          newTask.priority = [NSNumber numberWithInteger:priority];
  
          // push to parent
          if (![context save:&amp;error])
          {
              // handle error
          }
  
          // save parent to disk asynchronously
          [appDelegate.managedObjectContext performBlockAndWait:^{
              NSError *error;
              if (![appDelegate.managedObjectContext save:&amp;error])
              {
                  // handle error
              }
          }];
      }];
  
      if (!error) {
          return Success;
      } else {
          return Error;
      }
  }
  </code></pre>