程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字?

开发过程中遇到由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字的问题如何解决?下面主要结合日常开发的经验,给出你关于由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字的解决方法建议,希望对你解决由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字有所启发或帮助;

所以我的目标是在购买机票时始终有一个适当的增量值。我有一个奇怪的错误,当我通过增加字段值来更新字段值时,由于重复打印语句,每次运行新的模拟时它都会增加错误的数字,但是如果我要更新在同一个新模拟中再次取值,之后每次都会增加适当的值。

我用来递增的值是一个依赖于 UIStepper 值的标签文本。

这是我用来更新和增加这个值的完整函数:

func paymentAuthorizationVIEwController(_ controller: PKPaymentAuthorizationVIEwController,dIDAuthorizePayment payment: PKPayment,handler completion: @escaPing (PKPaymentAuthorizationResult) -> VoID) {
    
    guard let count = guestNumberCount.text else { return }
    guard let labelAsANumber = Int64(count) else { return }
    guard let user = Auth.auth().currentUser else { return }
    
    let dfmatter = DateFormatter()
    dfmatter.dateFormat = "EEEE,MMMM d yyyy,h:mm a"
    let dateFromString = dfmatter.date(from: actualDateOfEvent.text ?? "")
    let dateStamp: TimeInterval = dateFromString!.timeIntervalSince1970
    let dateSt: Int = Int(dateStamp)
    
    
    
    getStudentID { (studID) in
        if let ID = studID {
            self.db.document("student_users/\(user.uID)/events_bought/\(self.navigationItem.Title!)").setData(["event_name": self.navigationItem.Title!,"event_date": self.actualDateOfEvent.text ?? "","event_cost": self.actualCostOfEvent.text ?? "","for_grades": self.gradeOfEvent,"school_ID": ID,"expiresAt":dateSt,"isEventPurchased": true,"time_purchased": Date()],merge: true) { (error) in
                if let error = error {
                    print("There was an error trying to add purchase info to the database: \(error)")
                } else {
                    print("The purchase info was successfully stored to the database!")
                }
            }
        }
    }
    
    getdocumentIDOfSelectedEvent { (eventIDentification) in
        if let eventID = eventIDentification {
            self.getSchooldocumentID { (docID) in
                if let doc = docID {
                    self.db.document("school_users/\(doc)/events/\(eventID)/extraEventInfo/TicketCount").updateData(["ticketsPurchased": FIEldValue.increment(Int64(labelAsANumber))]) { (error) in
                        if let error = error {
                            print("There was an error updating the number of tickets: \(error)")
                        } else {
                            print("Number of tickets purchased succesfully updated!")
                            print(labelAsANumber)
                        }
                    }
                }
            }
        }
    }
    
    
    performSegue(withIDentifIEr: Constants.Segues.fromTicketFormtopurchaseDetails,sender: self)
    
    completion(PKPaymentAuthorizationResult(status: .success,errors: []))
}

我无法真正找出函数中的任何问题,无论是在我的整个项目中,还是在这种情况下,除了打印语句。在 print(labelAsANumber) 语句中,它打印了标签文本的正确值(步进值),但它打印了四次,这是导致问题的原因。如何防止这种重复的打印语句和整体不正确的数字递增?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字全部内容,希望文章能够帮你解决由于打印语句重复 4 次,firestore 文档中的字段值增加了错误的数字所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: