title: Sorting and Setting Default in CoreData List
body: <p>My iOS application uses <code>CoreData</code> to store many things, and <code>NSUserDefaults</code> to store other things that <code>CoreData</code> would be overkill for.</p>
  
  <p>I'm going to simplify this so bear with me (Note: for the sake of this example let's use credit cards). When my application loads it displays a list of saved credit cards. Now, when each card is added it is assigned a number 1-10 (let's call it <code>cardNum</code>) that stays with the card for the life of it. </p>
  
  <p>So we add one card and assign it #1. We add another card and assign it #2. Another... #3. We can set a default card that will be highlighted on launch by tapping it. What it does is saves the <code>cardNum</code> as the <code>cDefault</code> to <code>NSUserDefaults</code> to keep track of it (effectively setting card X as the default card). </p>
  
  <p>(crude drawing of a table view)</p>
  
  <pre><code>//cDefault is 2
  ------------
  1 - Card1
  ------------
  2 - Card2 (cDefault)
  ------------
  3 - Card3
  ------------
  4 - Card4
  ------------
  </code></pre>
  
  <p>So let's say we assign <code>cDefault</code> to 2 and then next week we delete that card. On deletion, I need to automatically assign one of the other cards to be a default card. </p>
  
  <p>(crude drawing of table view AFTER card 2 is deleted - note how <code>cDefault</code> is still set...)</p>
  
  <pre><code>//cDefault is still 2
  ------------
  1 - Card1
  ------------
  3 - Card3
  ------------
  4 - Card4
  ------------
  </code></pre>
  
  <p>So my question is how, upon deletion, to set another card as <code>cDefault</code> (i.e if it was an array I would probably set the new default to the <code>cDefault</code> value of whatever card is at  <code>indexPath.row==0</code> but I'm not sure if I can do that using <code>CoreData</code>)</p>
  
  <p>Please ask as many questions as you need to. I tried to explain this to the best of my abilities but if I was unclear on anything please ask me. </p>
  
  <p>Thank you so much in advance.
  James</p>