如何显示从一个视图向右或向左刷卡的更正和未更正计数

How to show corrected and incorrected count of card swiped either right or left from one view to another

在我的应用程序中,我使用 ZLSwipeable 库实现了刷卡功能。现在,当我向右滑动时,意味着答案正确,向左滑动则答案不正确。假设我有 5 张卡片,然后如果我向左滑动 2 个,向右滑动 3 个,那么更正后的计数应该是 2,不正确的计数应该是 3,它应该显示在另一个名为 Score VC 的屏幕上,它有 2 个标签用于更正和错误的计数。当我刷最后一张卡时,它应该导航到 Score VC,我如何实现它。首先翻转卡片,然后刷卡或单击。意味着翻转的卡片上也有两个按钮,向左滑动或单击勾选按钮,它具有相同的功能,向右滑动也是如此

我的 Flipcard VC 刷卡功能所在的代码:

class FlipCardVC: UIViewController, UIGestureRecognizerDelegate, AVSpeechSynthesizerDelegate
{

    @IBOutlet weak var exitTapPopup: UIView!
    @IBOutlet weak var cardFlipPopup: UIView!
    @IBOutlet weak var savePopup: UIView!
    @IBOutlet var hideCardPopup: UIView!
    @IBOutlet var audioAllowPopup: UIView!
    @IBOutlet weak var switchState: UISwitch!
    @IBOutlet weak var progressViewBar: UIProgressView!
    @IBOutlet weak var cardOuterView: UIView!


    var wordsData = [ModelResult]()
    var cardId = Int()

    var cardSoundIndex = 0

    //MARK: ZLSwipeableView Properties
    @IBOutlet weak var SwipeCardOuterView: UIView!
    var swipeableView: ZLSwipeableView!
    var colorIndex = 0
    var cardIndex = 0
    var loadCardsFromXib = false
    let speechSynthesizer = AVSpeechSynthesizer()

    var isCorrect: Bool = true
    var correctAnswerArr = [String]()
    var incorrectAnswerArr = [String]()

    var cardView:CardView? 

    var trueCounter = 0
    var falseCounter = 0
    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)

        constrain(SwipeCardOuterView, view) { view1, view2 in
            view1.left == view2.left
            view1.top == view2.top
            view1.width == view.bounds.width
            view1.height == view.bounds.height
        }
    }

    // MARK: CARD VIEW
    func cardInit()
    {

        wordsData.shuffle()
        swipeableView = ZLSwipeableView()
        view.addSubview(swipeableView)
        swipeableView.numberOfActiveView = 2
        swipeableView.didStart = {view, location in
            print("Did start swiping view at location: \(location)")

        }
        swipeableView.swiping = {view, location, translation in
            print("Swiping at view location: \(location) translation: \(translation)")

        }
        swipeableView.didEnd = {view, location in

            self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
            self.cardIndex += 1

            if self.swipeableView.direction == .Left
            {
                self.isCorrect = true
                self.correctAnswerArr.append("\(self.isCorrect)")
                print(self.correctAnswerArr.count)

                if self.colorIndex == self.wordsData.count
                {
                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                    vc.tempCorrectAnswer = "\(self.correctAnswerArr.count)"
                    self.navigationController?.pushViewController(vc, animated: true)
                }

            }
            else
            {
                self.isCorrect = false
                self.incorrectAnswerArr.append("\(self.isCorrect)")
                print(self.incorrectAnswerArr.count)

                if self.colorIndex == self.wordsData.count
                {
                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                    vc.tempincorrectAnswer = "\(self.incorrectAnswerArr.count)"
                    self.navigationController?.pushViewController(vc, animated: true)
                }

            }
        }
        swipeableView.didSwipe = {view, direction, vector in
            print("Did swipe view in direction: \(direction), vector: \(vector)")

            if direction.description == "Right"
            {
//                self.UserObject = self.UserData[view.tag]
//                self.API_POST_Favorite()
            }
            else
            {
//                self.UserObject = self.UserData[view.tag]
//                self.API_POST_UNFavorite()
            }

        }

        swipeableView.didCancel = {view in
            print("Did cancel swiping view")
        }

        swipeableView.didTap = {view, location in

            let cv = view as! CardView

            if cv.contentview.tag == 0 {
                cv.contentview.tag = 1
                UIView.transition(with: view, duration: 0.7, options: .transitionFlipFromRight, animations: {
                    if self.wordsData.count > cv.tag
                    {
                        let data = self.wordsData[cv.tag] as ModelResult
                        let tempLangChanged = UserDefaults.standard.bool(forKey: "isLangChanged")
                        if tempLangChanged != false
                        {
                            if let englishName = data.cardWordEnglish, englishName.count != 0
                            {
                                cv.contentview.wordLabel.text = englishName
                            }

                            cv.contentview.wordImage.isHidden = true
                            cv.contentview.yesNoBtnView.isHidden = false

                            cv.contentview.wordLabel.isUserInteractionEnabled = true
                            let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gr:)))
                            cv.contentview.wordLabel.addGestureRecognizer(tap)
                            tap.delegate = self

                            cv.contentview.yesBtn.tag = cv.tag
                            cv.contentview.noBtn.tag = cv.tag
                            cv.contentview.yesBtn.addTarget(self, action: #selector(self.yesBtnSwipeLeft), for: .touchUpInside)
                            cv.contentview.noBtn.addTarget(self, action: #selector(self.noBtnSwipeRight), for: .touchUpInside)

                            let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: data.cardWordEnglish!)
                            speechUtterance.rate = 0.3
                            speechUtterance.volume = 1.0
                            speechUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")
                            self.speechSynthesizer.speak(speechUtterance)

                        }
                        else
                        {
                            if let spanishName = data.cardWordSpanish, spanishName.count != 0
                            {
                                cv.contentview.wordLabel.text = spanishName
                            }

                            cv.contentview.wordImage.isHidden = true
                            cv.contentview.yesNoBtnView.isHidden = false

                            cv.contentview.wordLabel.isUserInteractionEnabled = true
                            let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gr:)))
                            cv.contentview.wordLabel.addGestureRecognizer(tap)
                            tap.delegate = self

                            cv.contentview.yesBtn.tag = cv.tag
                            cv.contentview.noBtn.tag = cv.tag

                            cv.contentview.yesBtn.addTarget(self, action: #selector(self.yesBtnSwipeLeft), for: .touchUpInside)
                            cv.contentview.noBtn.addTarget(self, action: #selector(self.noBtnSwipeRight), for: .touchUpInside)

                            let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: data.cardWordSpanish!)
                            speechUtterance.rate = 0.3
                            speechUtterance.volume = 1.0
                            speechUtterance.voice = AVSpeechSynthesisVoice(language: "es")
                            self.speechSynthesizer.speak(speechUtterance)

                        }
                    }
                }, completion: { (complete) in

                })
            }
        }
        swipeableView.didDisappear = { view in
            print("Did disappear swiping view")
        }

        constrain(swipeableView, view) { view1, view2 in
            view1.left == view2.left+5
            view1.right == view2.right-5
            view1.top == view2.top + 50 
            view1.bottom == view2.bottom - 16 + (IS_IPHONE_X() ? -24 : 0)

//            view1.left == view2.left+50
//            view1.right == view2.right-50
//            view1.top == view2.top + 120
//            view1.bottom == view2.bottom - 100

//            view1.left == view2.left+16
//            view1.right == view2.right-16
//            view1.top == view2.top + 83 + (IS_IPHONE_X() ? 24 : 0)
//            view1.bottom == view2.bottom - 16 + (IS_IPHONE_X() ? -24 : 0)
        }

        self.loadCardsFromXib = true
        self.colorIndex = 0
        self.swipeableView.discardViews()
        self.swipeableView.loadViews()
    }

    override func viewDidLayoutSubviews()
    {
        super.viewDidLayoutSubviews()
        if let swview = swipeableView
        {
            swview.nextView = {
                return self.nextCardView()
            }
        }
    }

    @objc func yesBtnSwipeLeft(sender: UIButton) {

        self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
        self.cardIndex += 1
        self.swipeableView.swipeTopView(inDirection: .Left)

            trueCounter = trueCounter + 1

    if colorIndex == self.wordsData.count{
                let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                UserDefaults.standard.set(trueCounter, forKey: "trueCounter")
                self.navigationController?.pushViewController(vc, animated: true)
            }
    }

    @objc func noBtnSwipeRight(sender: UIButton) {

        self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
        self.cardIndex += 1
        self.swipeableView.swipeTopView(inDirection: .Right)

            falseCounter = falseCounter + 1
        print("THIS IS my counter: (falseCounter)")
        if colorIndex == self.wordsData.count {
            let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
            UserDefaults.standard.set(falseCounter, forKey: "falseCounter")

            self.navigationController?.pushViewController(vc, animated: true)
        }

    }

    @objc func soundBtn(sender: UIButton)
    {
        ApiUtillity.sharedInstance.AddSubViewtoParentView(parentview: self.view, subview: self.audioAllowPopup)
    }

    @objc func hideCard(sender: UIButton)
    {
        ApiUtillity.sharedInstance.AddSubViewtoParentView(parentview: self.view, subview: self.hideCardPopup)
    }

    func nextCardView() -> UIView?
    {
        let arrayData = wordsData

        if (self.colorIndex >= arrayData.count)
        {
            return nil
        }

        self.cardView = CardView(frame: swipeableView.bounds)

            if loadCardsFromXib
            {
                self.cardView!.contentview = Bundle.main.loadNibNamed("CardContentView", owner: self, options: nil)?.first! as? CardView

                self.cardView!.contentview.superVC = self
                self.cardView!.contentview.translatesAutoresizingMaskIntoConstraints = false
                self.cardView!.contentview.backgroundColor = self.cardView!.backgroundColor
                self.cardView!.addSubview(self.cardView!.contentview)

                let data = arrayData[(self.colorIndex)] as ModelResult
                self.cardView!.contentview.wordModel = data

                self.cardView!.contentview.currentCardCountLbl.text = "\(self.colorIndex + 1)"+" "+"of"+" "+"\(wordsData.count)"

                let tempLangChanged = UserDefaults.standard.bool(forKey: "isLangChanged")

                if tempLangChanged == false
                {
                    if let dict = data.cardWordImage, dict.count != 0
                    {
                        let url = WS_wordIconUrl + dict
                        self.cardView!.contentview.wordImage.kf.indicatorType = .activity
                        self.cardView!.contentview.wordImage.kf.setImage(with: URL(string: url))
                    }

                    if let englishName = data.cardWordEnglish, englishName.count != 0
                    {
                        self.cardView!.contentview.wordLabel.text = englishName
                    }

                    cardView?.contentview.yesNoBtnView.isHidden = true

                }
                else
                {
                    if let dict = data.cardWordImage, dict.count != 0
                    {
                        let url = WS_wordIconUrl + dict
                        self.cardView!.contentview.wordImage.kf.indicatorType = .activity
                        self.cardView!.contentview.wordImage.kf.setImage(with: URL(string: url))
                    }

                    if let spanishName = data.cardWordSpanish, spanishName.count != 0
                    {
                        self.cardView!.contentview.wordLabel.text = spanishName
                    }

                     cardView?.contentview.yesNoBtnView.isHidden = true

                }

                self.cardView!.contentview.soundBtn.addTarget(self, action:#selector(self.soundBtn(sender:)), for: .touchUpInside)
                self.cardView!.contentview.hideCard.addTarget(self, action:#selector(self.hideCard(sender:)), for: .touchUpInside)

                self.cardView!.contentview.soundBtn.tag = self.colorIndex
                self.cardView!.contentview.hideCard.tag = self.colorIndex

                self.cardView!.tag = self.colorIndex
                constrain(self.cardView!.contentview, self.cardView!) { view1, view2 in
                    view1.left == view2.left
                    view1.top == view2.top
                    view1.width == self.cardView!.bounds.width
                    view1.height == self.cardView!.bounds.height
                }
            }

            colorIndex += 1
            return cardView

    }

    //MARK: API Parsing for deck words data

    func WS_GetWords()
    {
        if ApiUtillity.sharedInstance.isReachable()
        {

            ApiUtillity.sharedInstance.StartProgress(view: self.view)

            let url = "\(WS_GetWordsAPI)/\(cardId)"
            APIClient<ModelBaseGetWordsData>().API_GET(Url: url, Params: [:], Authentication: true, Progress: true, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (modelResponse) in

                if(modelResponse.success == true)
                {
                    ApiUtillity.sharedInstance.StopProgress(view: self.view)

                    self.colorIndex = 0
                    self.wordsData.removeAll()
                    if let array = modelResponse.result, array.count != 0
                    {
                        for data in array
                        {
                            self.wordsData.append(data)
                        }

                        self.cardInit()
                    }
                    else
                    {
                        self.colorIndex = 0
                        self.wordsData.removeAll()
                        DispatchQueue.main.asyncAfter(deadline: .now(), execute:
                        {
                            if self.swipeableView != nil
                            {
                                self.swipeableView.removeFromSuperview()
                            }
                            self.cardInit()
                        })
                    }
                }
                else
                {
                    self.showToast(message: modelResponse.message!)
                    ApiUtillity.sharedInstance.StopProgress(view: self.view)
                }

                if self.wordsData.count == 0
                {
                    self.setNoDataMessage(message: modelResponse.message)
                }
            }) { (failed) in
                self.showToast(message: failed.localizedDescription)
                ApiUtillity.sharedInstance.StopProgress(view: self.view)
            }
        }
        else
        {
            self.showToast(message: "No internet connection...")
        }
    }

我的分数vc代码:

    class ScoreVC: UIViewController {

        @IBOutlet weak var progressScoreView: MBCircularProgressBarView!
        @IBOutlet weak var correctAnswerLbl: UILabel!
        @IBOutlet weak var incorrectAnswerLbl: UILabel!

        var tempCorrectAnswer = String()
        var tempincorrectAnswer = String()

        override func viewDidLoad() {
            super.viewDidLoad()

            // Do any additional setup after loading the view.
            self.progressScoreView.value = 0.0

让正确 = UserDefaults.standard.string(forKey: "trueCounter")

let incorrect = UserDefaults.standard.string(forKey: "falseCounter")


self.correctAnswerLbl.text = correct
self.incorrectAnswerLbl.text = incorrect

        }
override func viewWillAppear(_ animated: Bool) {
        self.setCounterToZero()
        UIView.animate(withDuration: 10.0) {
            self.progressScoreView.value = 50.0
        }
    }
    func setCounterToZero(){
        correctAnswerLbl.text = ""
        incorrectAnswerLbl.text = ""
    }

创建 2 个 var 变量来增加值

var trueCounter = 0
var falseCounter = 0

在你的 ViewWillAppear 中设置一个函数,每次你的屏幕重新加载时,计数器也会这样做

override func viewWillAppear(_ animated: Bool) {
        setCounterToZero()

    }


    func setCounterToZero(){
        correctAnswerLbl.text = ""
        incorrectAnswerLbl.text = ""
    }

因此在您的滑动功能中设置变量以增加

为假:

 falseCounter = falseCounter + 1

为真

trueCounter = trueCounter + 1

当游戏结束并将用户发送到 ScoreVC 时

UserDefaults.standard.set(trueCounter, forKey: "trueCounter")
UserDefaults.standard.set(falseCounter, forKey: "falseCounter")

flipcardVC

class FlipCardVC: UIViewController, UIGestureRecognizerDelegate, AVSpeechSynthesizerDelegate
{

    @IBOutlet weak var exitTapPopup: UIView!
    @IBOutlet weak var cardFlipPopup: UIView!
    @IBOutlet weak var savePopup: UIView!
    @IBOutlet var hideCardPopup: UIView!
    @IBOutlet var audioAllowPopup: UIView!
    @IBOutlet weak var switchState: UISwitch!
    @IBOutlet weak var progressViewBar: UIProgressView!
    @IBOutlet weak var cardOuterView: UIView!


    var wordsData = [ModelResult]()
    var cardId = Int()

    var cardSoundIndex = 0

    //MARK: ZLSwipeableView Properties
    @IBOutlet weak var SwipeCardOuterView: UIView!
    var swipeableView: ZLSwipeableView!
    var colorIndex = 0
    var cardIndex = 0
    var loadCardsFromXib = false
    let speechSynthesizer = AVSpeechSynthesizer()

    var isCorrect: Bool = true
    var correctAnswerArr = [String]()
    var incorrectAnswerArr = [String]()
    var trueCounter = 0
    var falseCounter = 0
    var cardView:CardView? 


    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)

        constrain(SwipeCardOuterView, view) { view1, view2 in
            view1.left == view2.left
            view1.top == view2.top
            view1.width == view.bounds.width
            view1.height == view.bounds.height
        }
    }

    // MARK: CARD VIEW
    func cardInit()
    {

        wordsData.shuffle()
        swipeableView = ZLSwipeableView()
        view.addSubview(swipeableView)
        swipeableView.numberOfActiveView = 2
        swipeableView.didStart = {view, location in
            print("Did start swiping view at location: \(location)")

        }
        swipeableView.swiping = {view, location, translation in
            print("Swiping at view location: \(location) translation: \(translation)")

        }
        swipeableView.didEnd = {view, location in

            self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
            self.cardIndex += 1

            if self.swipeableView.direction == .Left
            {
                self.isCorrect = true
                self.correctAnswerArr.append("\(self.isCorrect)")
                print(self.correctAnswerArr.count)

                if self.colorIndex == self.wordsData.count
                {
                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                    vc.tempCorrectAnswer = "\(self.correctAnswerArr.count)"
                    self.navigationController?.pushViewController(vc, animated: true)
                }

            }
            else
            {
                self.isCorrect = false
                self.incorrectAnswerArr.append("\(self.isCorrect)")
                print(self.incorrectAnswerArr.count)

                if self.colorIndex == self.wordsData.count
                {
                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                    vc.tempincorrectAnswer = "\(self.incorrectAnswerArr.count)"
                    self.navigationController?.pushViewController(vc, animated: true)
                }

            }
        }
        swipeableView.didSwipe = {view, direction, vector in
            print("Did swipe view in direction: \(direction), vector: \(vector)")

            if direction.description == "Right"
            {
//                self.UserObject = self.UserData[view.tag]
//                self.API_POST_Favorite()
            }
            else
            {
//                self.UserObject = self.UserData[view.tag]
//                self.API_POST_UNFavorite()
            }

        }

        swipeableView.didCancel = {view in
            print("Did cancel swiping view")
        }

        swipeableView.didTap = {view, location in

            let cv = view as! CardView

            if cv.contentview.tag == 0 {
                cv.contentview.tag = 1
                UIView.transition(with: view, duration: 0.7, options: .transitionFlipFromRight, animations: {
                    if self.wordsData.count > cv.tag
                    {
                        let data = self.wordsData[cv.tag] as ModelResult
                        let tempLangChanged = UserDefaults.standard.bool(forKey: "isLangChanged")
                        if tempLangChanged != false
                        {
                            if let englishName = data.cardWordEnglish, englishName.count != 0
                            {
                                cv.contentview.wordLabel.text = englishName
                            }

                            cv.contentview.wordImage.isHidden = true
                            cv.contentview.yesNoBtnView.isHidden = false

                            cv.contentview.wordLabel.isUserInteractionEnabled = true
                            let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gr:)))
                            cv.contentview.wordLabel.addGestureRecognizer(tap)
                            tap.delegate = self

                            cv.contentview.yesBtn.tag = cv.tag
                            cv.contentview.noBtn.tag = cv.tag
                            cv.contentview.yesBtn.addTarget(self, action: #selector(self.yesBtnSwipeLeft), for: .touchUpInside)
                            cv.contentview.noBtn.addTarget(self, action: #selector(self.noBtnSwipeRight), for: .touchUpInside)

                            let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: data.cardWordEnglish!)
                            speechUtterance.rate = 0.3
                            speechUtterance.volume = 1.0
                            speechUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")
                            self.speechSynthesizer.speak(speechUtterance)

                        }
                        else
                        {
                            if let spanishName = data.cardWordSpanish, spanishName.count != 0
                            {
                                cv.contentview.wordLabel.text = spanishName
                            }

                            cv.contentview.wordImage.isHidden = true
                            cv.contentview.yesNoBtnView.isHidden = false

                            cv.contentview.wordLabel.isUserInteractionEnabled = true
                            let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gr:)))
                            cv.contentview.wordLabel.addGestureRecognizer(tap)
                            tap.delegate = self

                            cv.contentview.yesBtn.tag = cv.tag
                            cv.contentview.noBtn.tag = cv.tag

                            cv.contentview.yesBtn.addTarget(self, action: #selector(self.yesBtnSwipeLeft), for: .touchUpInside)
                            cv.contentview.noBtn.addTarget(self, action: #selector(self.noBtnSwipeRight), for: .touchUpInside)

                            let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: data.cardWordSpanish!)
                            speechUtterance.rate = 0.3
                            speechUtterance.volume = 1.0
                            speechUtterance.voice = AVSpeechSynthesisVoice(language: "es")
                            self.speechSynthesizer.speak(speechUtterance)

                        }
                    }
                }, completion: { (complete) in

                })
            }
        }
        swipeableView.didDisappear = { view in
            print("Did disappear swiping view")
        }

        constrain(swipeableView, view) { view1, view2 in
            view1.left == view2.left+5
            view1.right == view2.right-5
            view1.top == view2.top + 50 
            view1.bottom == view2.bottom - 16 + (IS_IPHONE_X() ? -24 : 0)

//            view1.left == view2.left+50
//            view1.right == view2.right-50
//            view1.top == view2.top + 120
//            view1.bottom == view2.bottom - 100

//            view1.left == view2.left+16
//            view1.right == view2.right-16
//            view1.top == view2.top + 83 + (IS_IPHONE_X() ? 24 : 0)
//            view1.bottom == view2.bottom - 16 + (IS_IPHONE_X() ? -24 : 0)
        }

        self.loadCardsFromXib = true
        self.colorIndex = 0
        self.swipeableView.discardViews()
        self.swipeableView.loadViews()
    }

    override func viewDidLayoutSubviews()
    {
        super.viewDidLayoutSubviews()
        if let swview = swipeableView
        {
            swview.nextView = {
                return self.nextCardView()
            }
        }
    }

    @objc func yesBtnSwipeLeft(sender: UIButton) {

        self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
        self.cardIndex += 1
        self.swipeableView.swipeTopView(inDirection: .Left)

             var finalTrue = 0
             trueCounter = trueCounter + 1
             print("THE USER SWIPE TO left")
             print("///////////////////////////////////////////")
             print(trueCounter)
             print("///////////////////////////////////////////")
             finalTrue = trueCounter
    if colorIndex == self.wordsData.count{
                let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
                UserDefaults.standard.set(finalTrue, forKey: "trueCounter")
                self.navigationController?.pushViewController(vc, animated: true)
            }
    }

    @objc func noBtnSwipeRight(sender: UIButton) {

        self.progressViewBar.progress = (Float(self.cardIndex + 1) / Float(self.wordsData.count))
        self.cardIndex += 1
        self.swipeableView.swipeTopView(inDirection: .Right)

            var finalFlase = 0
            falseCounter = falseCounter + 1
            print("THE USER SWIPE TO right")
             print("///////////////////////////////////////////")
             print(falseCounter)
             print("///////////////////////////////////////////")
            var finalFlase = falseCounter
        print("THIS IS my counter: (falseCounter)")
        if colorIndex == self.wordsData.count {
            let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScoreVC") as! ScoreVC
            UserDefaults.standard.set(finalFlase, forKey: "falseCounter")

            self.navigationController?.pushViewController(vc, animated: true)
        }

    }

    @objc func soundBtn(sender: UIButton)
    {
        ApiUtillity.sharedInstance.AddSubViewtoParentView(parentview: self.view, subview: self.audioAllowPopup)
    }

    @objc func hideCard(sender: UIButton)
    {
        ApiUtillity.sharedInstance.AddSubViewtoParentView(parentview: self.view, subview: self.hideCardPopup)
    }

    func nextCardView() -> UIView?
    {
        let arrayData = wordsData

        if (self.colorIndex >= arrayData.count)
        {
            return nil
        }

        self.cardView = CardView(frame: swipeableView.bounds)

            if loadCardsFromXib
            {
                self.cardView!.contentview = Bundle.main.loadNibNamed("CardContentView", owner: self, options: nil)?.first! as? CardView

                self.cardView!.contentview.superVC = self
                self.cardView!.contentview.translatesAutoresizingMaskIntoConstraints = false
                self.cardView!.contentview.backgroundColor = self.cardView!.backgroundColor
                self.cardView!.addSubview(self.cardView!.contentview)

                let data = arrayData[(self.colorIndex)] as ModelResult
                self.cardView!.contentview.wordModel = data

                self.cardView!.contentview.currentCardCountLbl.text = "\(self.colorIndex + 1)"+" "+"of"+" "+"\(wordsData.count)"

                let tempLangChanged = UserDefaults.standard.bool(forKey: "isLangChanged")

                if tempLangChanged == false
                {
                    if let dict = data.cardWordImage, dict.count != 0
                    {
                        let url = WS_wordIconUrl + dict
                        self.cardView!.contentview.wordImage.kf.indicatorType = .activity
                        self.cardView!.contentview.wordImage.kf.setImage(with: URL(string: url))
                    }

                    if let englishName = data.cardWordEnglish, englishName.count != 0
                    {
                        self.cardView!.contentview.wordLabel.text = englishName
                    }

                    cardView?.contentview.yesNoBtnView.isHidden = true

                }
                else
                {
                    if let dict = data.cardWordImage, dict.count != 0
                    {
                        let url = WS_wordIconUrl + dict
                        self.cardView!.contentview.wordImage.kf.indicatorType = .activity
                        self.cardView!.contentview.wordImage.kf.setImage(with: URL(string: url))
                    }

                    if let spanishName = data.cardWordSpanish, spanishName.count != 0
                    {
                        self.cardView!.contentview.wordLabel.text = spanishName
                    }

                     cardView?.contentview.yesNoBtnView.isHidden = true

                }

                self.cardView!.contentview.soundBtn.addTarget(self, action:#selector(self.soundBtn(sender:)), for: .touchUpInside)
                self.cardView!.contentview.hideCard.addTarget(self, action:#selector(self.hideCard(sender:)), for: .touchUpInside)

                self.cardView!.contentview.soundBtn.tag = self.colorIndex
                self.cardView!.contentview.hideCard.tag = self.colorIndex

                self.cardView!.tag = self.colorIndex
                constrain(self.cardView!.contentview, self.cardView!) { view1, view2 in
                    view1.left == view2.left
                    view1.top == view2.top
                    view1.width == self.cardView!.bounds.width
                    view1.height == self.cardView!.bounds.height
                }
            }

            colorIndex += 1
            return cardView

    }

    //MARK: API Parsing for deck words data

    func WS_GetWords()
    {
        if ApiUtillity.sharedInstance.isReachable()
        {

            ApiUtillity.sharedInstance.StartProgress(view: self.view)

            let url = "\(WS_GetWordsAPI)/\(cardId)"
            APIClient<ModelBaseGetWordsData>().API_GET(Url: url, Params: [:], Authentication: true, Progress: true, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (modelResponse) in

                if(modelResponse.success == true)
                {
                    ApiUtillity.sharedInstance.StopProgress(view: self.view)

                    self.colorIndex = 0
                    self.wordsData.removeAll()
                    if let array = modelResponse.result, array.count != 0
                    {
                        for data in array
                        {
                            self.wordsData.append(data)
                        }

                        self.cardInit()
                    }
                    else
                    {
                        self.colorIndex = 0
                        self.wordsData.removeAll()
                        DispatchQueue.main.asyncAfter(deadline: .now(), execute:
                        {
                            if self.swipeableView != nil
                            {
                                self.swipeableView.removeFromSuperview()
                            }
                            self.cardInit()
                        })
                    }
                }
                else
                {
                    self.showToast(message: modelResponse.message!)
                    ApiUtillity.sharedInstance.StopProgress(view: self.view)
                }

                if self.wordsData.count == 0
                {
                    self.setNoDataMessage(message: modelResponse.message)
                }
            }) { (failed) in
                self.showToast(message: failed.localizedDescription)
                ApiUtillity.sharedInstance.StopProgress(view: self.view)
            }
        }
        else
        {
            self.showToast(message: "No internet connection...")
        }
    }

并在你的分数标签中 分数 vc

override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.progressScoreView.value = 0.0
        let correct = UserDefaults.standard.string(forKey: "trueCounter")

        let incorrect = UserDefaults.standard.string(forKey: "falseCounter")


        self.correctAnswerLbl.text = correct
        self.incorrectAnswerLbl.text = incorrect

    }
override func viewWillAppear(_ animated: Bool) {
        //don't add setCounterToZero()
        UIView.animate(withDuration: 10.0) {
            self.progressScoreView.value = 50.0
        }
    }

如果有用请打分