title: Reordering tableview cells
body: <p>I a trying to re order cells based on their priority (an enum). I have double checked that my enum values are correct. Here is my enum </p>
  
  <pre><code>enum Priority{
      case low
      case neutral
      case high
      case urgent
  }
  </code></pre>
  
  <p>As you can see, the lower priority has lower hash values. I am trying to compare two cells;  a cell and the cell above it. If the cell's value is greater than the one above it, it will shift upwards. I obtain the IndexPath of the cell above using</p>
  
  <pre><code>var newIndexPath = IndexPath(row: indexPath.row - 1 , section: indexPath.section)
  </code></pre>
  
  <p>After comparing enum values using</p>
  
  <pre><code>if(comparePriority.hashValue &lt; priorityValue.hashValue)
  </code></pre>
  
  <p>I attempt to switch the order using </p>
  
  <pre><code>tableview.moveRow(at: indexPath, to: newIndexPath)
  </code></pre>
  
  <p>The result is interesting, I will use pictures to explain. Note that all of this code is in my <code>cellForRowAt</code> function and that all cells are given the priority that correspond with their name except for "test", also that these pictures were taken in slow motion meaning that the user wouldn't be able to actually see the switch happening.</p>
  
  <p>Mid-segue
  <a href="https://i.stack.imgur.com/amNNe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/amNNe.png" alt="Cells start switching"></a></p>
  
  <p>Cells finish switching
  <a href="https://i.stack.imgur.com/7WQ1D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7WQ1D.png" alt="Cells finish switching"></a></p>