gpt4 book ai didi

ios - 将 Eureka 表单数据上传到 firebase

转载 作者:可可西里 更新时间:2023-11-01 01:17:10 24 4
gpt4 key购买 nike

我有一个 Eureka 表单 View 的用户配置文件。在这个空间中,用户可以更新他们的个人资料。如果用户点击“保存”,它会调用此函数。

    func saveProfileSettings(){

let userID = user?.uid
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"

let PROFILE_DISPLAY_NAME_REF: NameRow? = form.rowBy(tag: Constants.PROFILE_DISPLAY_NAME)
let PROFILE_DISPLAY_NAME = PROFILE_DISPLAY_NAME_REF?.value

let PROFILE_EMAIL_REF: EmailRow? = form.rowBy(tag: Constants.PROFILE_EMAIL)
let PROFILE_EMAIL = PROFILE_EMAIL_REF?.value

let PROFILE_PHONENUMBER_REF: PhoneRow? = form.rowBy(tag: Constants.PROFILE_PHONENUMBER)
let PROFILE_PHONENUMBER = PROFILE_PHONENUMBER_REF?.value

let PROFILE_BIRTH_AGE_REF: DateRow? = form.rowBy(tag: Constants.PROFILE_BIRTH_AGE)
let PROFILE_BIRTH_AGE_CONVERT = PROFILE_BIRTH_AGE_REF?.value
let PROFILE_BIRTH_AGE = formatter.string(from: PROFILE_BIRTH_AGE_CONVERT!)
let PROFILE_BIRTH_AGE_String = String(PROFILE_BIRTH_AGE)

let PROFILE_GENDER_REF: SegmentedRow<String>! = form.rowBy(tag: Constants.PROFILE_GENDER)
let PROFILE_GENDER = PROFILE_GENDER_REF.value

let PROFILE_GENDER_INTEREST_REF: SegmentedRow<String>! = form.rowBy(tag: Constants.PROFILE_GENDER_INTEREST)
let PROFILE_GENDER_INTEREST = PROFILE_GENDER_INTEREST_REF.value

let uploadPath = databaseRef.child("profiles").child(userID!)

let dataBlock = ["\(Constants.PROFILE_DISPLAY_NAME)": PROFILE_DISPLAY_NAME!, "\(Constants.PROFILE_EMAIL)": PROFILE_EMAIL!, "\(Constants.PROFILE_PHONENUMBER)": PROFILE_PHONENUMBER!, "\(Constants.PROFILE_BIRTH_AGE)": PROFILE_BIRTH_AGE_String!, "\(Constants.PROFILE_GENDER)": PROFILE_GENDER!, "\(Constants.PROFILE_GENDER_INTEREST)": PROFILE_GENDER_INTEREST!]

print("DataBlock \(dataBlock)")

uploadPath.setValue(dataBlock) { (error, datebaseRef) in
if error != nil{
print("Error Occured")
}
print("Profile Updated!")
}



}

这个函数的工作是从表单中提取所有数据,将其放入一个数组中,然后将其上传到 firebase。如果用户单击保存并且不更新任何信息,一切都很好,但是如果他们编辑他们的个人资料并单击保存,则会导致错误。见下文。

assertion failed: Duplicate tag profileDisplayName: file /Users/brandonmayhew/Documents/Programming/X-Code Project's/ChristinaApp/Pods/Eureka/Source/Core/BaseRow.swift, line 172
2017-08-21 12:19:19.258586-0700 ChristinaApp[2615:926887] assertion failed: Duplicate tag profileDisplayName: file /Users/brandonmayhew/Documents/Programming/X-Code Project's/ChristinaApp/Pods/Eureka/Source/Core/BaseRow.swift, line 172

如果您想查看创建表单的代码是什么,它在我的“viewDidLoad”中

override func viewDidLoad() {
super.viewDidLoad()

self.startAnimating(Constants.animationSize, message: "Finding Your Profile", type: .ballZigZag)

//findImageURL()


//START

let userID = user?.uid
print("Logged in user: \(userID!)")


databaseRef.child("profiles").child(userID!).observe(.value, with: { (snapshot) in


let data = snapshot.value as? NSDictionary

let PROFILE_DISPLAY_NAME = data?[Constants.PROFILE_DISPLAY_NAME] as? String
let PROFILE_UID = data?[Constants.PROFILE_UID] as? String
let PROFILE_IMAGE = data?[Constants.PROFILE_IMAGE] as? String
let PROFILE_EMAIL = data?[Constants.PROFILE_EMAIL] as? String
let PROFILE_PHONENUMBER = data?[Constants.PROFILE_PHONENUMBER] as? String
let PROFILE_GENDER = data?[Constants.PROFILE_GENDER] as? String
let PROFILE_GENDER_INTEREST = data?[Constants.PROFILE_GENDER_INTEREST] as? String
let PROFILE_BIRTH_AGE = data?[Constants.PROFILE_BIRTH_AGE] as? String
let PROFILE_LATITUDE = data?[Constants.PROFILE_LATITUDE] as? String
let PROFILE_lONGITUDE = data?[Constants.PROFILE_lONGITUDE] as? String

self.form +++ Section("Personal Information")

<<< NameRow(){ row in

row.title = "Name"
row.placeholder = "Enter Name"
row.value = PROFILE_DISPLAY_NAME
row.tag = "\(Constants.PROFILE_DISPLAY_NAME)"

}

<<< EmailRow(){ row in

row.title = "Email"
row.placeholder = "Enter Email"
row.value = PROFILE_EMAIL
row.tag = "\(Constants.PROFILE_EMAIL)"

}

<<< PhoneRow(){ row in

row.title = "Phone Number"
row.placeholder = "Enter Phone Number"
row.value = PROFILE_PHONENUMBER
row.tag = "\(Constants.PROFILE_PHONENUMBER)"

}

<<< DateRow(){ row in
row.title = "Your Birth Year"

//Convert 'PROFILE_BIRTH_AGE' string to NSDATE
let date = NSDate()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let formattedDate = dateFormatter.date(from: PROFILE_BIRTH_AGE!)

row.value = formattedDate
row.tag = "\(Constants.PROFILE_BIRTH_AGE)"
}



+++ Section("Dating Settings")

<<< SegmentedRow <String> (){ row in
row.title = "I am"
row.options = ["Male", "Female"]
row.value = PROFILE_GENDER
row.tag = "\(Constants.PROFILE_GENDER)"
}

<<< SegmentedRow <String> (){ row in
row.title = "I'm interested in"
row.options = ["Male", "Female"]
row.value = PROFILE_GENDER_INTEREST
row.tag = "\(Constants.PROFILE_GENDER_INTEREST)"
}

+++ Section("Save Profile")
<<< ButtonRow() {
$0.title = "Save"
}
.onCellSelection { cell, row in

self.saveProfileSettings()

}

+++ Section("Come Back Later")
<<< ButtonRow() {
$0.title = "Sign Out"
}
.onCellSelection { cell, row in

self.signOut()
}




self.stopAnimating()


})

//STOP


}

我不知道是什么导致了这个错误!

最佳答案

您遇到的问题是由添加具有相同标记字符串值的行或部分引起的。在 Eureka Forms 中,单元格甚至部分的标签应该是唯一的,因此如果您添加具有相同标签的 2 行,这将导致断言异常

您在代码的多个部分中都有这种行为,但我将以名称行为例

 <<< NameRow(){ row in

row.title = "Name"
row.placeholder = "Enter Name"
row.value = PROFILE_DISPLAY_NAME
row.tag = "\(Constants.PROFILE_DISPLAY_NAME)"

}

如您所见,row.tag = "\(Constants.PROFILE_DISPLAY_NAME)" 这是导致问题的行,我假设 Constants.PROFILE_DISPLAY_NAME 是一个String 在项目的某些部分定义,这个字符串不会改变,当你要从这个方法添加你的第二个结果时

databaseRef.child("profiles").child(userID!).observe(.value, with: { (snapshot) in

您的应用程序崩溃是因为您第二次使用相同的值“profileDisplayName”添加 Constants.PROFILE_DISPLAY_NAME

解决这个问题的方法

作为此问题的可能解决方案,您可以为每个获取的用户附加一个唯一值,比如 userID

NameRow 大小写的固定代码

 <<< NameRow(){ row in

row.title = "Name"
row.placeholder = "Enter Name"
row.value = PROFILE_DISPLAY_NAME
row.tag = "\(Constants.PROFILE_DISPLAY_NAME)\(userID)"

}

关于ios - 将 Eureka 表单数据上传到 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45804253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com