Search code examples
swiftexceptionrealmxcode7.1

error: execution was interrupted, reason: breakpoint 1.2. Xcode 7.1, Swift


So the context is that I made a realm object and is giving one of it's variables a value, to do this I go ahead and call an instance of this object, then I connect to my server, get some value, then say something like

    let someObject = someObjectClass() //this being a realm object class

    someQuerySuccessBlock { (success, error) -> void in
        ...
        if let someValue = objects[0].value {
            someObject.id = someValue    //this line is where the issue is
        }
        ...
    })

    let realm = RLMRealm.defaultRealm()
    realm.beginWriteTransaction
    realm.addObject(someObject)
    realm.commitWriteTransaction

Error in llvm is error: execution was interrupted, reason: breakpoint 1.2. Error does not show unless i make a breakpoint for all exceptions.

Also to note that code does compile, does run, will not cause a crash (but simply.. not run any of the code from that specific line onwards. That someObject does get saved and created, but the field that is to be assigned simply did not get assigned, etc


Solution

  • After some testing around, turns out this is because the realm object was already saved into Realm, where as the query block is async, it was trying to write into a variable of an object that had already been added.

    Seems like the error was only like this because what I was trying to edit was the primaryKey of the object?

    My fix:

        let someObject = someObjectClass() //this being a realm object class
    
        someQuerySuccessBlock { (success, error) -> void in
            ...
            if let someValue = objects[0].value {
                someObject.id = someValue    //this line is where the issue is
    
                let realm = RLMRealm.defaultRealm()
                realm.beginWriteTransaction
                realm.addObject(someObject)
                realm.commitWriteTransaction
            }
            ...
        })