Start a new topic
Answered

KCSUser collection attributes

 Is that possible to add more fields to the user collections or we have to create separate collections then use queries to get the data we want?


In my app,  the user has more than just username and email. I am not sure what is the best way to deal with this problem.



Thanks

Best Answer

Hi Charles,


Sorry if I was unclear before. Following are a couple of code snippets I think would solve this issue.

  • Sign up a new user with an extra field

  

[KCSUser
	userWithUsername:@"kinvey"
	password:@"12345"
	fieldsAndValues:@{KCSUserAttributeEmail : @"kinvey@kinvey.com", KCSUserAttributeGivenname : @"Arnold", KCSUserAttributeSurname : @"Kinvey", @"dob" : @"07-05-61"}
	withCompletionBlock:^(KCSUser user, NSError errorOrNil, KCSUserActionResult result) {
              if (errorOrNil == nil)
              {
                  //was successful!
              }
              else
              {
                  //there was an error with the sign up
              }
	}];

  

  • Add a new field for a logged in user

 

[user setValue:@"NYC" forAttribute:@"city"];
[user saveWithCompletionBlock:^(NSArray objectsOrNil, NSError errorOrNil) {
    if (errorOrNil == nil) {
       //was successful!
    } else {
       //there was an error with the update save
    }
}];

 

  • View a field other than preset values - e.g. date of birth - dob

 

NSLog(@"User's date of birth is - %@", [[user valueForKeyPath:@"userAttributes"] valueForKey:@"dob"]);

 


Regards,

Wani


Hi Charles,


You can add as many fields as you want to the user collection. E.g. first name, last name, date of birth etc.



Regards,

Wani

 do I do it in the console? because everytime I add an extra column it just disappears after I refresh the page.

You have two options to achieve this:

  1. Using the console, add the new column and then add value for that column for one or more users.
  2. Update KCSUser class definition with the new column and then update/add one or more users with values for the new column.


Regards,

Wani

How do I update the KCSUser class definition? I cant seem to make it work correctly

 

Answer

Hi Charles,


Sorry if I was unclear before. Following are a couple of code snippets I think would solve this issue.

  • Sign up a new user with an extra field

  

[KCSUser
	userWithUsername:@"kinvey"
	password:@"12345"
	fieldsAndValues:@{KCSUserAttributeEmail : @"kinvey@kinvey.com", KCSUserAttributeGivenname : @"Arnold", KCSUserAttributeSurname : @"Kinvey", @"dob" : @"07-05-61"}
	withCompletionBlock:^(KCSUser user, NSError errorOrNil, KCSUserActionResult result) {
              if (errorOrNil == nil)
              {
                  //was successful!
              }
              else
              {
                  //there was an error with the sign up
              }
	}];

  

  • Add a new field for a logged in user

 

[user setValue:@"NYC" forAttribute:@"city"];
[user saveWithCompletionBlock:^(NSArray objectsOrNil, NSError errorOrNil) {
    if (errorOrNil == nil) {
       //was successful!
    } else {
       //there was an error with the update save
    }
}];

 

  • View a field other than preset values - e.g. date of birth - dob

 

NSLog(@"User's date of birth is - %@", [[user valueForKeyPath:@"userAttributes"] valueForKey:@"dob"]);

 


Regards,

Wani

Login or Signup to post a comment