ios User Addproperty not working

Hello Backendless,
I have petProfile table which has the relationship with users.
user: petProfile has 1:N relationship for sure.
When I add a pet, I try to use ‘AddProperty’ bcs I need to add an object into petProfile array in user table.
I can store petProfile well but cannot add this object using AddProperty. Can u check why?
let _ = user.addProperty([“petProfiles” : result!]) → responds nothing


Backendless.sharedInstance().data.save(profile, response: { (result) in
 print("PetProfile havs been added: \(result!)") 
 dump(result)
 let _ = user?.addProperties(["petProfiles" : result!])
 completionHandler(true)
 }) { (Fault) in
 print("Server reported an error: \(Fault?.description)")
 completionHandler(false)
 }


Hey KenChoi

I’ve shared the topic with our iOS developer and he will answer you asap.

Regards, Vlad

Hi KenChoi,

Please attach your code as text, not screenshot

Regards,
Olha

 
 
 
 
 
 
func uploadPetProfile(profile: PetProfile, completionHandler: @escaping (_ success: Bool) -> ()) {
 
 
 
 
 let user = Backendless.sharedInstance().userService.currentUser 
 
 
 
 
 Backendless.sharedInstance().data.save(profile, response: { (result) in 
 
 print("PetProfile havs been added: \(result!)") 
 
 dump(result) 
 
 let _ = user?.addProperties(["petProfiles" : result!]) 
 
 completionHandler(true) 
 
 }) { (Fault) in 
 
 print("Server reported an error: \(Fault?.description)") 
 
 completionHandler(false) 
 
 } 
 
 }


You should use setProperty method instead of addProperties.
Also you don’t save your changes.
Add
self.backendless.data.save(user)
after
let _ = user?.setProperty(“petProfiles”, object:result!)

Regards,
Olga

Hi Olga,
The reason I ask this question is that I want to add current instance object into existing array, not set the current instance replacing existing array. Am i understanding right?

Please, check this topic.

You can retrieve all existing relations in array, add new relations to this array and save it.

Regards,
Olha

Yes, I try to use user property function bcs it seems like simpler one I can take.

I will try ur comment above ^^;;

Hello KenChoi,
Is your problem solved?

Regards,
Olga

Yes, I solved in this way

  • first, get the property in the user
  • change as I want
  • second, use ‘setProperty’
  • Third, update user

Thanks for ur help ^^

Hello,

Glad to hear that. Have a nice day.

Regards, Olga

Yeap but please clarify that ‘AddPropery’ function usage.
Quite confuse those functions in the user class

Thanks for ur help once again ^^