Are Queries Permitted/Valid Inside a Write Transaction?

This may help - from the docs

The Swift SDK represents each transaction as a callback function that contains zero or more read and write operations. To run a transaction, define a transaction callback and pass it to the realm’s write method. Within this callback, you are free to create, read, update, and delete on the realm. If the code in the callback throws an exception when Realm runs it, Realm cancels the transaction. Otherwise, Realm commits the transaction immediately after the callback.

So that boils down to all or none. It either all passes or all fails as it’s “one thing”. Whatever happens in the transaction, stays in the transaction.

The process can be illustrated by some example code.

In this case, I have a PersonClass object and each person has a name and desc property. The code loads them in, queries for me (Jay) with the property desc set to Jays Desc and then updates my description to “Hello, World”.

The fetched Jay is printed before, and then after the update (you’ll see it’s updated) but then throws an exception so nothing was committed.

do {
    try realm.write {
        let people = realm.objects(PersonClass.self)
        let jayBefore = people.where { $0.name == "Jay" }.first!
        print(jayBefore.name, jayBefore.desc)
        jayBefore.desc = "Hello, World" //update the description
        let jayAfter = people.where { $0.name == "Jay" }.first!
        print(jayAfter.name, jayAfter.desc)
        throw "Throwing"
    }
} catch let err as NSError {
    print(err.localizedDescription)
}

and the output

Jay Jays desc   //this is before the update
Jay Hello, World  //this is after the update
The operation couldn’t be completed. (Swift.String error 1.)  //throw causing the transaction to cancel

If we then retrieve Jay again, it’s unchanged.

Jay Jays desc //back to it's original value

So - the data within the write block is scoped to that block and only changes within that block.

Does that clarify it?