0
votes

I pass it from previous view controller. I want show data that I save in other view controller.

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "Beacons") {


        let nav = segue.destinationViewController as! UINavigationController
        let svc = nav.topViewController as! BeaconCharacteristicViewController
        svc.selectedList = sender as! Beacons


    }

and

      var selectedList : Beacons!

and this code that error for some reason.

i don't use a primary key or i have to use it.

    func loadproperties(){

      let beacons = selectedList

      let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT

      dispatch_async(dispatch_get_global_queue(priority, 0)) {

        do{
            try uiRealm.write({ () -> Void in

                beacons.uuid = self.beaconUUID.text!
                print("uuid = \(beacons.uuid)")

                beacons.major = self.beaconMajor.text!
                print("uuid = \(beacons.uuid)")

                beacons.minor = self.beaonMinor.text!
                print("uuid = \(beacons.uuid)")

                uiRealm.add(beacons, update: true)

                }
            )
        } catch {
            print("error")
        }

       }
    }

Error

       Terminating app due to uncaught exception 'RLMException', reason: 'Realm accessed from incorrect thread.'

Thank You :)))

1

1 Answers

2
votes

Based on your code try uiRealm.write, it seems that you call realm instance of another thread in the main thread (dispatch block). Try create another instance.

    do{
        // create new instance
        let uiRealm = try! Realm()

        try uiRealm.write({ () -> Void in

            beacons.uuid = self.beaconUUID.text!
            print("uuid = \(beacons.uuid)")

            beacons.major = self.beaconMajor.text!
            print("uuid = \(beacons.uuid)")

            beacons.minor = self.beaonMinor.text!
            print("uuid = \(beacons.uuid)")

            uiRealm.add(beacons, update: true)

            }
        )
    } catch {
        print("error")
    }