Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to @ggfela for his answer. The processes of his answer were spot on. Here is the actual code I put into my button/method, in hopes of it helping someone else in the future:</p> <pre><code>NSArray *moc = [[self fetchedResultsController] fetchedObjects]; for (ActiveListData *item in moc) { if (item != nil &amp;&amp; item.isChecked.boolValue == 1) { item.isChecked = [NSNumber numberWithBool:NO]; item.isActive = [NSNumber numberWithBool:NO]; } } // Call to Data Store to update the list NSError *error; if (![self.managedObjectContext save:&amp;error]) { FATAL_CORE_DATA_ERROR(error); return; </code></pre> <p><strong>Explanation:</strong></p> <p>Load the contents of the result from calling the <code>fetchedResultsController</code> method into a temporary variable named <code>moc</code></p> <p>Use a <code>for</code> loop to cycle through the array of <code>moc</code>. <code>ActiveListData</code> is the NSManagedObject subclass that I created for my Core Data and is the proper place to insert the separated values/attributes from the data store. From there, it's pretty simple, I ensure that <code>item</code> is not <code>nil</code> AND that the item's attribute is the value I need. </p> <p><strong>NOTE</strong> </p> <p>Core Data does not store the bool values YES and NO but rather 1 and 0, respectively but when you call or compare the values, you simply can not compare the value of <code>item.isChecked</code> because it is being passed back to you as a bool not as an integer. You can not simply compare <code>item.isChecked == YES</code> either since the <code>@property</code> of <code>isChecked</code> is an <code>NSNumber</code>. So, in the case of the <code>if</code> I put <code>item.isChecked.boolValue</code> as this will give me the representing integer for it's bool value, in this case I have it check for a 1 (YES). (Sorry if my explanation is wrong and/or confusing, but this is how I understand it and is the only way this code works.)</p> <p>Then, setting the new values of these attributes is like you would expect when setting any other variable. The only "tricky" difference with this is that the NSManagedObject subclass sets the <code>@property</code> of the <code>isChecked</code> and <code>isActive</code> to an <code>NSNumber</code> (as mentioned earlier) so in order to send the proper values back to Core Data you use the method <code>numberWithBool</code> of the <code>NSNumber</code> class.</p> <p>And just in case anyone gets confused by my <code>FATAL_CORE_DATA_ERROR(error)</code> call this is simply a macro that was defined inside the <code>Prefix.pch</code> file to handle my errors from the managedObjectContext. You can use any (or none) error handling you choose.</p> <p>Thanks again @ggfela for your help!! If anyone else has any other suggestions on how this code should be applied, then please let me know!</p>
    singulars
    1. This table or related slice is empty.
    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