Skip to content

Retrieving User Properties

Description

This operation allows retrieving user properties from the BackendlessUser object stored locally in the client application.

Method

BackendlessUser *user = // some BackendlessUser object

// retrieves value of a property with the specified name
id value = user.properties[@"propertyName"];

// retrieves all properties for the user object
NSDictionary *properties = user.properties;

// removes the property identified by the name
NSMutableDictionary *userProperties = [NSMutableDictionary dictionaryWithDictionary:user.properties];
[userProperties removeObjectForKey:@"propertyName"];
user.properties = userProperties;

// removes all properties identified by names
NSMutableDictionary *userProperties = [NSMutableDictionary dictionaryWithDictionary:user.properties];
[userProperties removeObjectsForKeys:@[@"propertyName1", @"propertyName2"]];
user.properties = userProperties;
let user = // some BackendlessUser object

// retrieves value of a property with the specified name
let value = user.properties["propertyName"]

// retrieves all properties for the user object
let properties = user.properties

// removes the property identified by the name
user.properties.removeValue(forKey: "propertyName")

// removes all properties identified by names
let propertyNames = ["propertyName1", "propertyName2"]
for propertyName in propertyNames {
    user.properties.removeValue(forKey: propertyName)
}

Return Value

An object containing properties and corresponding values.

{  
  "propName1" : value,  
  "propName2": value,   
}

Example

The example below logs in as "alice@yourmail.com" and retrieves the phoneNumber user property.

[Backendless.shared.userService loginWithIdentity:@"alice@yourmail.com" password:@"wonderland" responseHandler:^(BackendlessUser *loggedInUser) {
    NSString *phoneNumber = loggedInUser.properties[@"phoneNumber"];
    if (phoneNumber) {
        NSLog(@"User's email: %@, phoneNumber: %@", loggedInUser.email, phoneNumber);
    }
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.userService.login(identity: "alice@yourmail.com", password: "wonderland", responseHandler: { loggedInUser in
    if let email = loggedInUser.email,
       let phoneNumber = loggedInUser.properties["phoneNumber"] as? String {
        print("User's email: \(email), phoneNumber: \(phoneNumber)")
    }
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})