Iterate through the custom Analysis column in the Swift application

I want to know how I can save the entire user column (a user column Pointer<_User>from a user class) and put them all in an array variable so that I can see if the user exists in this class or not, This is what I have:

Old code

    var objectUserIdArray = [String]()
    let objectUserIdQuery : PFQuery = PFQuery(className: "Scores")

    objectUserIdQuery.findObjectsInBackgroundWithBlock {
        (objects : [PFObject]? , error : NSError?) -> Void in

        var objectID = objects! as [PFObject]

        for i in 0..<objectID.count {
            objectUserIdArray.append(objectID[i].objectId!)
        }

        for _ in objectID {
            print(objectUserIdArray)
        }

New code

func saveScoresOnParse() {
    objectUserIdQuery.whereKey("User", equalTo: PFObject(withoutDataWithClassName: "_User", objectId: userID))

    objectUserIdQuery.findObjectsInBackgroundWithBlock {
        (objects : [PFObject]? , error : NSError?) -> Void in
        if error == nil {

            //var objectID = objects! as [PFObject]

            /*for i in 0..<objectID.count {
                self.objectUserIdArray.append( objectID[i].objectId! )
            }*/

            for _ in objects! {
                print(objects)
            }

            // The score key has been incremented
            for (var i = 0 ; i < self.objectUserIdArray.count ; i++) {
                if self.userID != objects![i] {
                    print("New Scores")
                    print("R: \(self.rightAnswers)")
                    print("W: \(self.wrongAnswers)")
                    print("S: \(self.skippedQuestions)")
                    self.scores["User"] = PFUser.currentUser()
                    self.scores["Right"] = self.rightAnswers
                    self.scores["Wrong"] = self.wrongAnswers
                    self.scores["Skipped"] = self.skippedQuestions
                    self.scores.saveInBackground()

                } else if self.userID == objects![i] {
                    print("Updated Scores")
                    self.scores.incrementKey("Right", byAmount: 1)
                    self.scores.incrementKey("Wrong", byAmount: 1)
                    self.scores.incrementKey("Skipped", byAmount: 1)
                    print("R: \(self.rightAnswers)")
                    print("W: \(self.wrongAnswers)")
                    print("S: \(self.skippedQuestions)")
                    self.scores.saveInBackgroundWithBlock {
                        (success: Bool, error: NSError?) -> Void in
                        if (success) {
                            // The score key has been incremented
                        } else {
                            // There was a problem, check error.description
                        }
                    }

                } else {
                    print("Error")
                }
            }
        } else {
            print(error)
        }
    }

But it only stores the column objectId, not the column Pointer<_User>. I know this because when I print the material that is inside, it prints objects.

, , , , . , if , , , , . ( if if , ...)

material that happens

+4
1

, ;

Parse Score. - - . Parse; , Parse, .

, ; , , .

, , "" , .

func saveScoresOnParse() {
    if let currentUser=PFUser.currentUser() {
       let scoreQuery= PFQuery(className: "Scores")
       scoreQuery.whereKey("User",equalTo:currentUser)
       scoreQuery.getFirstObjectInBackgroundWithBlock {
        (object : PFObject? , error : NSError?) -> Void in
           if error == nil {
              var scoreObject=object ?? PFObject.objectWithClassName("Scores")
              if (scoreObject["User"]==nil) {
                 scoreObject["User"]=currentUser
              }
              scoreObject["Right"]=self.rightAnswers
              scoreObject.saveInBackground()
           } else {
              print(error)
           }
       }
    } else {
       print("No current user!")
    }
}
0

Source: https://habr.com/ru/post/1615345/


All Articles