快速将数据发送到Firestore数据库时出现问题

时间:2019-12-18 17:22:37

标签: swift google-cloud-firestore

我正在尝试将数据发送到Firestore数据库,我创建了一个请求,但是当我遇到一个请求时,它崩溃了,并显示错误消息Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Unsupported type: __SwiftValue'。我明白了为什么它崩溃的原因是我试图在params字典中发送我的结构数据,这就是为什么它崩溃了,我想发送包含播放器名称和播放器图像的数据数组,这是我的代码,

func saveTeamAPI()
{
    let image = teamImage.image
    let data = image!.jpegData(compressionQuality: 1.0)

    let getTeamData = TeamData(teamName: self.teamNameTxt.text!, teamImage: "James", playerArray: self.playerArray)

    let dbRef = Firestore.firestore()
    var ref: DocumentReference? = nil
    ref = dbRef.collection("Team").document()
    let docId = ref?.documentID
    print(docId)
    let params : [String : Any] = [

        "teamName": getTeamData.teamName ?? "",
        "teamImage": getTeamData.teamImage ?? "",
        "players": getTeamData.playerArray ?? []
    ]
    ref?.setData(params)
    {
        (error) in

        if let error = error
        {
            print("Error is \(error)")
        }
        else
        {
            print("Document added with ID: \(ref!.documentID)")
        }
    }
}

这是我的团队数据结构,

struct TeamData {

var teamName : String?
var teamImage : String?
var playerArray : [PlayerData]?

var dictionary : [String:Any]
{
    return [

        "teamName" : teamName ?? "",
        "teamImage" : teamImage ?? "",
        "players" : playerArray ?? []
    ]
}

} 那就是我的playerdata数组

struct PlayerData {

var playerName : String?
var playerDetail : String?
var playerImage : [UIImage]?

var dictionary : [String:Any]
{
    return [

        "playerName" : playerName ?? "",
        "playerImage" : playerImage ?? "",
        "playerDetail" : playerDetail ?? ""
    ]
}

}

0 个答案:

没有答案