Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To start you need a data model to reflect what you want to save, in this case, some text and a date. So:</p> <pre><code>DatedText{ savedText:String dateSaved:Date } </code></pre> <p>To create a new <code>DatedText</code> object (without a custom class) do:</p> <pre><code>NSManagedObject *newDatedText; newDatedText=[NSEntityDescription insertNewObjectForEntityForName:@"DateText" inManagedObjectContext:theManagedObjectContext]; [newDatedText setValue:someText forKey:@"savedText"]; [newDatedText setValue:aDateObject forKey:@"dateSaved"]; NSError *saveError=nil; [theManagedObjectContext save:&amp;saveError]; if (saveError!=nil) { NSLog(@"[%@ saveContext] Error saving context: Error=%@,details=%@",[self class], saveError,saveError.userInfo); } </code></pre> <p>To retrieve a <code>DatedText</code> object with a specific date you create a fetch like so:</p> <pre><code>NSFetchRequest *fetch=[[NSFetchRequest alloc] init]; NSEntityDescription *testEntity=[NSEntityDescription entityForName:@"DatedText" inManagedObjectContext:self.moc]; [fetch setEntity:testEntity]; NSPredicate *pred=[NSPredicate predicateWithFormat:@"dateSaved==%@", targetDate]; [fetch setPredicate:[NSArray arrayWithObject:pred]]; NSError *fetchError=nil; NSArray *fetchedObjs=[theManagedObjectContext executeFetchRequest:theFetch error:&amp;fetchError]; if (fetchError!=nil) { NSLog(@" fetchError=%@,details=%@",fetchError,fetchError.userInfo); return nil; } </code></pre> <p><code>fetchedObjs</code> will now contain an array of all <code>DatedText</code> objects with the same <code>savedDate</code> as <code>targetDate</code>.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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