Start a new topic
Answered

Add new properties to User iOS 3.0

How can I add new properties / attributes to a user that is created. The example code in the documentation does not seem to work or I am having problems following it. Thanks!

Best Answer
Mark,

Refer to the documentation here for a CustomUser class:
http://devcenter.kinvey.com/ios-v3.0/guides/users#CustomAttributesCustomUserObject


Lets say, you wanted to add a ‘city’ field to as well. Here is what you would do:

class CustomUser: User {

    var address: String?
    var city: String?

    override func mapping(map: Map) {
        super.mapping(map)

        address <- map["address"]
        city <- map["city"]
    }

}

// Set the userType to “CustomUser”
Kinvey.sharedClient.userType = CustomUser.self

// Then you would set the variables appropriately
 user2.address = “2011 Apt B"
 user2.city = “Chicago”

// Then save it
user2.save()

// You should see both the fields added to the user entity in “Users” collection


Thanks,
Pranav
Kinvey Support

 


Answer
Mark,

Refer to the documentation here for a CustomUser class:
http://devcenter.kinvey.com/ios-v3.0/guides/users#CustomAttributesCustomUserObject


Lets say, you wanted to add a ‘city’ field to as well. Here is what you would do:

class CustomUser: User {

    var address: String?
    var city: String?

    override func mapping(map: Map) {
        super.mapping(map)

        address <- map["address"]
        city <- map["city"]
    }

}

// Set the userType to “CustomUser”
Kinvey.sharedClient.userType = CustomUser.self

// Then you would set the variables appropriately
 user2.address = “2011 Apt B"
 user2.city = “Chicago”

// Then save it
user2.save()

// You should see both the fields added to the user entity in “Users” collection


Thanks,
Pranav
Kinvey Support

 

 Hi Pranav,


Could you help how to create  above the "user2" object in IOS3.0 version.I  have used  "fieldsAndValues" property in earlier version but not able convert to this in ios3.0


Kinvey.sharedClient.userType = CustomUser.self
       
 User.signup(username: "test@gmail.com", password: "test", client: Kinvey.sharedClient, completionHandler: {}

Kannan,

Take a look at this code, it should help.

 

User.signup(username: “username", password: “password", client: Kinvey.sharedClient) { user, error in
       
            if let _ = user {
                var user2: CustomUser?
                user2 = (user as! CustomUser)
                user2?.address = “Boston"
                user2!.save()
                       
                } else {
                        //do something!
                }
        }

 


Thanks,

Pranav

Kinvey Support



Thanks Pranav..Now it is working fine.

 

Login or Signup to post a comment