Any idea how can I create a boolean user property and implement it in my code?

It is a switch that give the option to the user to be either a driver or a rider. This is the registration code so far, and every time I add the code for that new variable (the switch state) the registration does not work and shows the displayAlertMessage. If anyone can help I really appreciate it. Thank you

        Types.tryblock({ () -> Void in

            

            let user = BackendlessUser()

            user.email = self.username.text

            user.password = self.password.text

           

            var isDriver = true

            isDriver = self.`switch`.on

            

            //self.backendless.userService.registering(user)

            user.setProperty("isDriver", object: self.isDriver)

            self.backendless.userService.update(user)

            

            var registeredUser = self.backendless.userService.registering(user)

            

            //let registeredUser = self.backendless.userService.registering(user)

            

            print("User has been registered")




            }, catchblock: { (exception) -> Void in

                

                self.displayAlert("Sign up Failed", message: "Please try again")

                print("Server reported an error: \(exception as! Fault)")

        })

Javier, you don’t need ‘update’ before ‘registering’ - simply call ‘registering’ (you’ve got an alert because an user, what you are trying to update, is not exist):


Types.tryblock({ () -> Void in
let user = BackendlessUser()
user.email = self.username.text
user.password = self.password.text
var isDriver = self.`switch`.on
user.setProperty("isDriver", object: isDriver)
let registeredUser = self.backendless.userService.registering(user)
print("User has been registered: \(registeredUser)")
}, catchblock: { (exception) -> Void in
self.displayAlert("Sign up Failed", message: "Please try again")
print("Server reported an error: \(exception as! Fault)")
})

I have coded this way as well but the displayAlert pops up with no registration completed, and I have in the backendless dashboard the same name for the custom boolean property, and everything looks fine, at least what I was able to read online…

Are you talking about the “Sign up Failed” alert?

Yeah no matter if I enter an email and a passowrd it pops up constantly, so that is the code, followed by API Cookbook, and github for the registration page, but it is not working, the new propoerty, isnt working either, and I have changed the code depending on recommendations the entire day but still is not working as it’s supposed to

This means the code receives an exception which would contain information describing what went wrong. See this page in the doc and try to get error code and error message from the Fault object:

https://backendless.com/documentation/users/ios/users_error_handling.htm

The problem is that no errors appear, a couple of exeptions in the line of self.isDriver = self.‘switch’.on and a line that is commented out, this is the chunk of code for the sign up method, at some point today I got to registered but with the new property still not working, and now I cannot even register again. And the thing is that the code for the registering part looks the same, except that i dont have registeredUser() in viewDidload, becuase it gives me a error. Also I have the constant variable of appID, VersionNum, and SecretKey at the app delegate, in the viewController I just have backendless.sharedInstance().

@IBAction func signUp(sender: AnyObject) {




    if username.text == "" || password.text == ""{

     

        displayAlert("Missing Field(s)", message: "Username and Password are required")

        

    }else {

        

        Types.tryblock({ () -> Void in

            

            let user = BackendlessUser()

            user.email = self.username.text

            user.password = self.password.text

        

            user.setProperty("isDriver", object: self.isDriver)

            

            self.isDriver = self.`switch`.on

            

            self.backendless.userService.registering(user)

            //self.backendless.userService.update(user)

            

            let registeredUser = self.backendless.userService.registering(user)

            

            print("User has been regitered: \(registeredUser)")

            

            }, catchblock: {(exception) -> Void in

                

                self.displayAlert("Sign up Failed", message: "Please try again")

                print("Server reported an error (SYNC): \(exception as! Fault)")

        })

        

        

    }




}

Thank you Mark

You can see the error in the debugger. Just a set a breakboint in the “catchblock” and inspect the value of the “exception” variable.

Firstly, thank you very much, the problem was that I had name as a required field by mistake, nevertheless with that code now the user is getting registered but the displayAlert keeps showing as if something went wrong and in the debugger it says

Server reported an error (SYNC): FAULT = ‘3011’ [Property ‘password’ is required] <Property ‘password’ is required>
and I am inputing a password but it is not saved in backendless, if a don’t input anything in the password textfield a different displayAlert message appear. And how about the switch variable isDriver, I have created already the property as a boolean in the backendless console, but I can’t get it to work. thank you!

Hi Mark, the password and email, seem to be working fine now, but the isDriver switch still has no effect on the data base, no matter in which position it is at the time of registration. it appears like this and I tried to set the default value, as true, as false and as null, and it did not make any difference

Welcome new Driver

User has been regitered: <BackendlessUser [<BackendlessUser: 0x7ff63604b4f0>]> {

"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"password\",\"created\",\"___saved\",\"___class\",\"name\",\"isDriver\",\"ownerId\",\"updated\",\"email\",\"objectId\"],\"relatedObjects\":{}}";

created = "2016-05-05 23:35:28 +0000";

email = "***********@******.com";

isDriver = 0;

name = "&lt;null&gt;";

objectId = "41C6F630-C5E0-AA63-FF5F-4416C6CDDB00";

ownerId = "41C6F630-C5E0-AA63-FF5F-4416C6CDDB00";

updated = "&lt;null&gt;";

userStatus = "EMAIL_CONFIRMATION_PENDING";

}

Please ignore my previous post. So you’re saying that you’re changing the default value of the iDriver column on the server to Yes, No, Null and the assigned value is not loaded to the client?

Yeah, so now the default value is true, but everytime I sign up, the value for every user is false no matter if I change the switch for each of them or not. here is the code for the registration with that switch. Now it is registering but it seems it is ignoring the switch functionality.

@IBAction func signUp(sender: AnyObject) {




    if username.text == "" || password.text == ""{

     

        displayAlert("Missing Field(s)", message: "Username and Password are required")

        

    }else {

        

        Types.tryblock({ () -> Void in

            

            let user = BackendlessUser()

            user.email = self.username.text

            user.password = self.password.text

            

            var isDriver = true

            

            //isDriver = self.`switch`.on

            

            if isDriver == self.`switch`.on{

                

                var isDriver = false

                user.setProperty("isDriver", object: self.isDriver)

                

                print("Welcome new Driver")

                

            }else{

                

                var isDriver = true

                user.setProperty("isDriver", object: self.isDriver)

                

                print("welcome new Rider!!")

                

            }

            

            //self.isDriver = self.`switch`.on

            //self.backendless.userService.registering(user)

            //self.backendless.userService.update(user)

            

            let registeredUser = self.backendless.userService.registering(user)

            

            print("User has been regitered: \(registeredUser)")

            

            }, catchblock: {(exception) -> Void in

                

                self.displayAlert("Sign up Failed", message: "Please try again")

                print("Server reported an error (SYNC): \(exception as! Fault)")

        })

        

        

    }




}

Thank you Mark

This is an update on the issue. It is still not working. Property created Boolean isDriver, default value true. Every time a user is registered it is registered as false…Any idea why is that happening?

I managed to get it done, thank you all for your help. In case it might help someone else who is doing the same, I will paste here the code that worked for me.

var isDriver = self.switch.on

user.setProperty(“isDriver”, object: isDriver)

if isDriver != self.switch.on{

var isDriver = false

print(“Welcome new Rider”)

}else{

    var isDriver = true

    print("welcome new Driver!!")

                

            }