Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get Attributes from Core Data into an Array for - iPhone SDK
    text
    copied!<p>I'm trying to retrieve data from Core Data and put it into a Mutable Array</p> <p>I have an Entity called 'Stock' and in Properties, attributes called : code, price &amp; description...</p> <p>How do I get the data stored in these attributes into a simple Mutable Array?</p> <hr> <p>I've added this code...</p> <pre><code>NSMutableArray *array = [[NSMutableArray alloc]init]; [array addObject:[stock valueForKey:@"code"]]; </code></pre> <p>and I get this error...</p> <pre><code>'-[NSCFArray insertObject:atIndex:]: attempt to insert nil' </code></pre> <p>I have a 'Managed Object Class' called 'Stock' and declared called stock. Am I missing something?</p> <hr> <p>If I do this in the <code>-cellForRowAtIndexPath</code>...</p> <pre><code>Stock *stock1 = [fetchedResultsController objectAtIndexPath:indexPath]; array = [[NSMutableArray alloc] init]; [array addObject:stock1.code]; NSLog(@"Filtered List is? %@", array); </code></pre> <p>In the console I can see these 2 items</p> <pre><code>'The Filtered array is 810005' 'The Filtered array is 810007 </code></pre> <p>'</p> <p>What must I do to get these items(810005 &amp; 810007) into an array set up in the <code>-viewDidLoad</code> method? Like it does in the <code>-cellForRowAtIndexPath</code>?</p> <h2>Update</h2> <p>Hi Marcus,</p> <p>Finally got it working (well, 80%)</p> <p>I put this in the <code>-cellForRowAtIndexPath</code></p> <pre><code>Stock *product = nil; if (tableView == self.searchDisplayController.searchResultsTableView) { filteredListContent = [NSMutableArray arrayWithObjects:stock1.code, nil]; product = [self.filteredListContent objectAtIndex:indexPath.row]; [self configureFilteredCell:cell atIndexPath:indexPath]; [filteredListContent objectAtIndex:indexPath.row]; NSLog(@"Filtered List Array List is? %@", stock1.code); } else { listContent = [NSMutableArray arrayWithObjects:stock1.code, nil]; [self configureCell:cell atIndexPath:indexPath]; NSLog(@"List Array List is? %@", stock1.code); } </code></pre> <p>Then I used this code in the scope</p> <pre><code>- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { self.savedSearchTerm = searchText; if (searchText !=nil) { NSPredicate *predicate =[NSPredicate predicateWithFormat:@"code beginsWith[cd] %@", searchText]; [fetchedResultsController.fetchRequest setPredicate:predicate]; } else { NSPredicate *predicate =[NSPredicate predicateWithFormat:@"code contains[cd] %@", searchText]; [fetchedResultsController.fetchRequest setPredicate:predicate]; [self.tableView reloadData]; } NSError *error = nil; if (![[self fetchedResultsController] performFetch:&amp;error]) { // Handle error NSLog(@"Unresolved error %@, %@", error, [error userInfo]); exit(-1); // Fail } [self.tableView reloadData]; </code></pre> <p>Everything is filtering fine but when I hit cancel on the search, it's not reloading the original data...</p> <p>I won't be defeated...!!</p> <p>Thanx</p>
 

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