Skip to content

Instantly share code, notes, and snippets.

@mrh-is
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrh-is/9e2683d6c9a27127e13a to your computer and use it in GitHub Desktop.
Save mrh-is/9e2683d6c9a27127e13a to your computer and use it in GitHub Desktop.
RLMResults iteration issue
class MyObject: RLMObject {
dynamic var property: Int = 0
}
// Create some data
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
for i in 1...6 {
realm.addObject(MyObject())
}
realm.commitWriteTransaction()
// Change all the properties to 1
let results = MyObject.objectsWhere('property == 0')
realm.beginWriteTransaction()
for result in results {
let result = result as MyObject
result.property = 1 // This invisibly mutates the results array
}
realm.commitWriteTransaction() // Only every other MyObject gets changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment