Skip to content

Set User Properties

Description

Before updating the BackendlessUser object you must set new values or new properties locally in the application using the operation described in this topic. Then you have to use the Update User Object operation to send the locally saved data to Backendless servers to update the Users data table.

Important

When setting or updating a user property, the values must be of "primitive" data types (boolean, string, number, date). To assign a non-primitive value, use the Data relation API .

When registering a new user, the methods below can be used on the new BackendlessUser object. When updating an existing user, the BackendlessUser object representing the user must be retrieved from the server (either via login or the data object retrieval APIs).

Method

BackendlessUser *user = [BackendlessUser new];

// adds the new property to the user object
NSMutableDictionary *userProperties = [NSMutableDictionary dictionaryWithDictionary:user.properties];
userProperties[@"newProperty"] = propertyValue;
user.properties = userProperties;

// clears (removes) all user properties and replaces them with the specified collection
user.properties = @{@"propertyName": propertyValue};
let user = BackendlessUser()
// sets the new property to the user object
user.properties["newProperty"] = propertyValue

// clears (removes) all user properties and replaces them with the specified collection
user.properties = ["propertyName": propertyValue]

Return Value

None.

Example

The example below sets a new value "342-821-3802" for the property "phoneNumber" locally in the application.

If this property is new and does not exist in the Users data table, then upon the update operation a new column is created with the specified value. This behavior is available only if the Dynamic Schema Definition option is activated.

BackendlessUser *user = [BackendlessUser new];

// adds the new property to the user object if it does not exist. Updates this property if it already exists. 
NSMutableDictionary *userProperties = [NSMutableDictionary dictionaryWithDictionary:user.properties];
userProperties[@"phoneNumber"] = @"342-821-3802";
user.properties = userProperties;

// clears (removes) all user properties and replaces them with the specified collection
user.properties = @{@"phoneNumber": @"342-821-3802"};
let user = BackendlessUser()
// adds the new property to the user object if it does not exist. Updates this property if it already exists. 
user.properties["phoneNumber"] = "342-821-3802"

// clears (removes) all user properties and replaces them with the specified collection
user.properties = ["phoneNumber": "342-821-3802"]