samedi 27 juin 2015

Can't use information from DynamoDB scan

I am building a sign up/log in system in an iOS app using swift. I have a DynamoDB table set up, and I can send and load data from that table. However, I've run into a problem when I try to scan the table. I'm using the scan to check and make sure the emails, usernames, and passwords are original. The scan function works and brings all the data down, but when I try to use the data like when I say:

let results = task.result as! AWSDynamoDBPaginatedOutput

                for r in results.items{

                    if (self.emailTextField.text == r.userEmail){

                        self.emailMessageLabel.hidden = false
                        self.emailTextField.text = nil

                    }

the whole function gets confused. Because what it does is checks to see if emailTextField is equal to any of the results, and even if it is once, all of the other times it's not. So it will say that the emailMessageLabel.hidden is true as many times as emailTextField is not equal to anything, and false the one time that it is. So essentially the answer is both true and false, and I can't use that data. How do I fix this? I've been trying to fix it for days. I'll attach all the code that I've been trying to use.

Scan Function

func verifyAndActivateAccount(expression : AWSDynamoDBScanExpression) {
    self.emailMessageLabel.hidden = true
    self.nameMessageLabel.hidden = true
    self.passwordMessageLabel.hidden = true
    let tableRow = DDBTableRow()
    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()

    dynamoDBObjectMapper.scan(DDBTableRow.self, expression: expression) .continueWithExecutor(BFExecutor.mainThreadExecutor(),
        withBlock: { (task:BFTask!) -> AnyObject! in
            if (task.error == nil) {
                let results = task.result as! AWSDynamoDBPaginatedOutput

                for r in results.items{

                    if (self.emailTextField.text == r.userEmail){

                        self.emailMessageLabel.hidden = false


                    }
                    if (self.nameTextField.text == r.UserID) {

                        self.nameMessageLabel.hidden = false


                    }
                    if (self.passwordTextField.text == r.userPassword){

                        self.passwordMessageLabel.hidden = false


                    }



                }



            }else{

                self.giveSignUpAlert("Scan didn't work.")

            }

            return nil

    })

}

Button is Pressed

@IBAction func storeRegisterInfo(sender: UIButton) {
    let exp = AWSDynamoDBScanExpression()
    self.verifyAndActivateAccount(exp)
    //Check for original info
    let tableRow = DDBTableRow()
    tableRow?.UserID = self.nameTextField.text
    tableRow?.userEmail = self.emailTextField.text
    tableRow?.userPassword = self.passwordTextField.text

    let userEmail = emailTextField.text
    let userName = nameTextField.text
    let userPassword = passwordTextField.text
    let userConfirm = confirmTextField.text



    if userPassword != userConfirm {

        giveSignUpAlert("Your Passwords Don't Match!")

    }
    if (self.passwordTextField.text == self.confirmTextField.text) {
        if (userEmail.isEmpty || userName.isEmpty || userPassword.isEmpty || userConfirm.isEmpty){

            giveSignUpAlert("All Field Are Required")

        }else{

            self.insertDataIntoTable(tableRow)

        }

    }


}

Aucun commentaire:

Enregistrer un commentaire