Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire, ObjectMapper, Realm --> Save Responsedata in Realm

In my app I'm using Alamofire, ObjectMapper and Realm. I want to achieve, that the data (an array of objects) gets persisted in realm after the response was mapped. I have created an class of type Object, Mappable and the mapping is working. The data is written in realm and there is no error in realm in the write transaction. If I query the data from realm I get the objects I have saved but each property is empty. Do you have an idea why the data is not saved when the mapping is successful?

AlamofireManager.Configured
            .request(.GET, URLs.sharedInstance.getContactsUrl())
            .responseArray("contactHeaders") { (response: Response<[ParticipantData], NSError>) in


                if let participantsArray = response.result.value{
                    successHandler(participantsArray)

                    do{
                        try self.realm.write{
                            self.realm.add(participantsArray, update: true)
                        }
                    }
                    catch let err as NSError {
                        print("Error with realm: " + err.localizedDescription)
                    }
                }
like image 421
netshark1000 Avatar asked Nov 27 '25 21:11

netshark1000


1 Answers

When defining your Realm data model classes, you must ensure that their properties are declared dynamic. This exposes the properties to ObjC code and allows the values to be persisted.

like image 175
Sandy Chapman Avatar answered Nov 29 '25 15:11

Sandy Chapman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!