Last active
August 29, 2015 14:10
-
-
Save mrh-is/9e2683d6c9a27127e13a to your computer and use it in GitHub Desktop.
RLMResults iteration issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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