[EP] Improving the iCloud sync

:  ~ 45 sec read

When I wrote about iCloud sync, I said the sync logic is the shittiest ever, so this is the first attempt at improving it.

Firstly, the migrateOldData got an update:

EPEvent.data << EPEvent(
  id: Events.last?.id ?? 0 + 1,
  ...
)

init(...) {
  modificationTime = NSDate.timeIntervalSinceReferenceDate()
}

modifyEventInAnyWay() {
  modificationTime = NSDate.timeIntervalSinceReferenceDate()
}

Then the sync.

for iCloudEvent in document.data {
  var addEvent = true
        
  for localEvent in Events where localEvent.id == iCloudEvent.id {
    if localEvent.lastModification < iCloudEvent.lastModification {
    // Update local events.
    }
    
    // Inner if block instead of adding it in the where statement,
    // because if iCloud modification is older than local
    // we don't want to add a new event, just not update the local one
    addEvent = false
  }
  
  // Add new event.
  if addEvent { Events.append(iCloudEvent) }