title: UICollectionView Update Animated
body: <p>I got a UICollectionView and a rest api. I fetch my data and save it to arrays with entity objects I created. I've got entity objects which represent a user, a connection between two users and notifications (so the user can grand a connection between users).</p>
  
  <p>I present all my data inside a UICollectionView, which has 3 sections for the users profile, notifications and his connections to other users. Each got an own prototype cell with an own custom class.</p>
  
  <p>When I load my ViewController and start updating the data (fetching from api), I save a hash to track if the data has changed. If it has changed towards the currently displayed data, I save my new data objects to my data model and call a method "updateUI()" at my ViewController.</p>
  
  <p>So far so good, everything works - but I want my CollectionView to do the updates animated.</p>
  
  <p>I searched through the internet and read that the CollectionView has already methods for adding and deleting cells. But in my case I can not track how my data has changed, I only know that it has changed if the hash has changed.</p>
  
  <p>So when I call "reloadData()" in my "updateUI()"-method the whole CollectionView flashes up and the update is pretty ugly.</p>
  
  <p>How can I keep track how my data has changed, or how can I animate the datachange when displayed to the CollectionView in my "updateUI()"-method?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>To start with some code here is my data handler, which holds all the data for my views:</p>
  
  <pre><code>class DataHandler {
  
    static var connections : [Connection] = []
    static var ownProfile : User?
    static var notifications : [Notification] = []
    static var connectionsHash : String? = nil
    static var ownProfileHash : String? = nil
    static var notificationsHash : String? = nil
    static var overviewHash : String? = nil
  
    //plus getter and setter for every attribute
  }
  </code></pre>
  
  <p>This is how I store my json objects from the api into my datahandler, for example the notifications:</p>
  
  <pre><code>var notifications : [Notification] = []
  for (_,notification):(String, JSON) in dataObject["notifications"] {
    let notificationObj = Notification(json: notification)
    notifications.append(notificationObj)
  }
  DataHandler.setNotifications(notifications)
  </code></pre>
  
  <p>And in my View Controller I set up the cells with data from DataHandler:</p>
  
  <pre><code>  func collectionView(collectionView: UICollectionView,      cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
  
      var cell : UICollectionViewCell!
  
      let notificationCell = collectionView.dequeueReusableCellWithReuseIdentifier("NotificationCell", forIndexPath: indexPath) as! NotificationCell
      let ownProfileCell = collectionView.dequeueReusableCellWithReuseIdentifier("OwnProfileCell", forIndexPath: indexPath) as! OwnProfileCell
      let overviewUserCell = collectionView.dequeueReusableCellWithReuseIdentifier("OverviewUserCell", forIndexPath: indexPath) as! OverviewUserCell
  
      switch indexPath.section {
      case 0:
        //setting up cell for notification
        //with data from DataHandler
        cell = notificationCell
      case 1:
        //setting up cell for own profile
        //with data from DataHandler
        cell = ownProfileCell
      case 2:
        //setting up cell for connected user
        //with data from DataHandler
        cell = overviewUserCell
      default: break
  
      }
      return cell
    }
  </code></pre>
  
  <p>A typical response from my api looks like this:</p>
  
  <pre><code>{
    "success": true,
    "data": {
      "notifications": [
        {
          "id": 6,
          "lastAlarm": 1460493400,
          "alarmDelay": 0,
          "routine": 20000,
          "master": {
            "email": "*********",
            "id": 12,
            "created": 1454117165,
            "imageUrl": "http://192.168.2.171:9999/profileimages/4.jpg",
            "name": "**********",
            "lastReport": 1460857863
          },
          "active": false
        }
      ],
      "connections": [
        {
          "id": 3,
          "slave": {
            "email": "*********",
            "id": 12,
            "created": 1454117165,
            "imageUrl": "http://192.168.2.171:9999/profileimages/4.jpg",
            "name": "**********",
            "lastReport": 1460857863
          },
          "alarmDelay": 20000,
          "lastAlarm": 1460493400,
          "routine": 2000,
          "active": true
        },
        {
          "id": 4,
          "slave": {
            "email": "********",
            "id": 13,
            "created": 1454957407,
            "imageUrl": "http://192.168.2.171:9999/profileimages/5.jpg",
            "name": "*******",
            "lastReport": 0
          },
          "alarmDelay": 2000,
          "lastAlarm": 1460493400,
          "routine": 200,
          "active": true
        }
      ],
      "profile": {
        "id": 11,
        "shortestInterval": 300,
        "imageUrl": "http://192.168.2.171:9999/profileimages/3.jpg",
        "email": "********",
        "created": 1454117103,
        "name": "******",
        "lastReport": 1461674777
      }
    },
    "hash": "1c402ff86c8a3f9b7c0b2376d736fe47",
    "error": null
  }
  </code></pre>
  
  <p>And when I receive data from my api successfully I call the method updateUI in my ViewController:</p>
  
  <pre><code>  func updateUI(animated : Bool) {
      self.userCollectionView.reloadData()
    }
  </code></pre>
  
  <p>I also got some animations for cells, but only by first loading:</p>
  
  <pre><code>  func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
      if(duration == 0.5) {
        cell.layer.opacity = 0.0
        UIView.animateWithDuration(duration, animations: {
          cell.layer.opacity = 1.0
        })
      }
    }
  </code></pre>