Start a new topic

Can you store an array of strings in the Custom Attributes for a user?


Can I store an array of strings in the Custom Attributes of users?



I store arrays, dictionaries, and all sorts of objects as a part of my user objects. Works great.

As a precaution, I make sure anything I store as a part of the user object is NSJSONSerializable. Don't know if this is necessary, but it gives me peace of mind.
Ok cool, so when you set the value of a attribute do you have to worry about erasing the data or will it delete the previous data before it adds the new data?

Is there a way to make a class NSJSONSerializable and just store that in there? Right now I am storing an array of object ids and then going to go get those ids. Would it be more efficient to store the whole JSON object on the user?



1) I believe [KCSUser setValue: forAttribute:] overwrites an existing value (if it exists). My current logic depends on that and I haven't had an issue with it.

2) I work in a split backend environment where my user objects come from Kinvey, but my data objects (and associated iOS models) come from another REST API. I have never tried to store custom, subclassed NSObjects as a part of my user objects. I do however, store the JSON serialized versions of some of my custom objects as a part of my user attributes. However, when I store them, I use NSDictionaries, not the custom objects themselves.
So basically you take the NSObject and convert it to JSON and then store it on the user object. Then when you need it you pull the JSON and convert it back to the NSObject
Sort of...I get back JSON from my other API, representing model objects. I always NSJSSONSerialize them into dicts, arrays, etc. If I need to use them in the app, I convert them to custom classes. If I need to store them as a part of the user object, I don't bother with custom classes and just write the dicts, arrays to the KCSUser object as an attribute.

This way I know that no matter where the converted JSON is coming from (either the KCSUser or my other API) I know I am dealing with dicts and arrays. Also helps as I use the KCSUser attributes as something of a local cache for my API in the event the user is offline.
Cool man. Thanks for the help!
Login or Signup to post a comment