---
title: "[EP] iCloud sync"
slug: ep-icloud-sync
section: tech
date: 2015-06-20T19:46:00.000Z
canonical: https://roland.leth.ro/blog/tech/ep-icloud-sync
---

I already love Swift 2.0.

First, `defer`, to never forget to `enableUpdates` for the `query`:

```swift
query.disableUpdates()
defer { query.enableUpdates() }
// Do stuff.
```

Secondly, `for x in y where condition` loops:

```swift
for iCloudEvent in document.data {
  // I know, I know, worst sync ever; I will try to improve it at some point.
  for localEvent in Events where localEvent.name == iCloudEvent.name {
    // Update local events.
  }
  // Append to local events.
}
```