gpt4 book ai didi

ios - firebase childByAutoId.key 是可选的

转载 作者:行者123 更新时间:2023-11-30 11:02:42 29 4
gpt4 key购买 nike

我正在使用 Firebase 和 Swift。我想使用 Firebase 函数 childByAutoId.key 但它不起作用。我做错了什么? .key 是可选的...通常它必须是非可选的!感谢您的帮助!

import Foundation
import FirebaseDatabase

class AddWatchlistAPI {


var REF_WATCHLIST = Database.database().reference().child("watchlists")


static var shared: AddWatchlistAPI = AddWatchlistAPI()
private init() {
}

//add a watchlist to the user
func addWatchlistToDatabase(watchlistName: String, onSuccess: @escaping () -> Void) {

let watchlistRef = REF_WATCHLIST
let watchlistId = watchlistRef.childByAutoId().key //.key is optional ???? --> Normally it isn t optional

let newWatchlistRef = watchlistRef.child(watchlistId)//here the error is warning

}

}

最佳答案

尝试如下

1- 让 watchlistId:String = (watchlistRef.childByAutoId().key)!

2- 让 watchlistId:String = watchlistRef.childByAutoId().key ?? “”

3-

var ref: DatabaseReference!

ref = Database.database().reference()

let llave = self.ref.child(name_of_child).childByAutoId().key

关于ios - firebase childByAutoId.key 是可选的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53130985/

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