After migrating mine OS X application from swift 2.2 to swift 3.0 (realm version has also changed from 1.0.2 to 2.1.1) some of write transactions began to throw an exception: "Cannot create asynchronous query while in a write transaction". But it was working fine before the migration.

```
let realm = try Realm()
let allMessages = realm.objects(Message.self)
let messages = allMessages.filter("(state == 1) AND (dateSent <= %@)",  dateSent)
try realm.write ({
   messages.forEach { message in message.state = .seen }
})

```

At the beginning of the transaction it throws an exception. Why this is happening and how could I fix it?