Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you are having this issue in your <code>-viewDidLoad</code>, I am guessing (and without the code from <code>-viewDidLoad</code>, it is only a guess) that you are trying to fetch objects from the <code>NSFetchedResultsController</code> before the <code>-executeFetch:</code> has been called on the controller and therefore you are in the land of nils.</p> <p>I would suggest setting a break point in your <code>-viewDidLoad</code> and watching the values and you walk through your code. This will tell you what is <code>nil</code> and where.</p> <p>Of course a better question is, why are you trying to put <code>NSManagedObject</code> instances into a <code>NSMutableArray</code>? Since they are already in your <code>NSFetchedResultsController</code> is there really a need to build up another array? What is the end goal?</p> <h1>Update</h1> <p>Now I understand what you are trying to do. </p> <h2>Solution 1</h2> <p>Only populate the array when a search has been conducted. Take a look at the <a href="http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html" rel="nofollow noreferrer">http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html</a> example code and you should see how to apply it to your situation.</p> <p>If you want to <em>enter</em> the table view with a pre-defined search then you need to perform it after you have executed a <code>-performFetch:</code> in the <code>NSFetchedResultsController</code>.</p> <h2>Solution 2</h2> <p>Modify the <code>NSPredicate</code> on the <code>NSFetchedResultsController</code> to include your search terms and then execute <code>-performFetch:</code> on the <code>NSFetchedResultsController</code>, you may have to do a <code>-reloadData</code> on the table as well, I am not sure. </p> <p>When the user clears the search field you reset the predicate and re-fetch everything. Since it is all cached there should be no performance penalty.</p> <p>Solution 2 just occurred to me and I have not tested it personally but there is no reason it shouldn't work just fine. Should even give you live updates within the search.</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