Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase设置值在IOS 10、Swift 3中不起作用_Ios_Swift_Firebase_Firebase Realtime Database_Exc Bad Access - Fatal编程技术网

Firebase设置值在IOS 10、Swift 3中不起作用

Firebase设置值在IOS 10、Swift 3中不起作用,ios,swift,firebase,firebase-realtime-database,exc-bad-access,Ios,Swift,Firebase,Firebase Realtime Database,Exc Bad Access,当我试图将评论保存到Firebase时,我的应用程序正在崩溃。此代码在Xcode 8更新之前运行良好: func saveNewComment(){ //get date let date = Date() let calendar = Calendar.current let components = (calendar as NSCalendar).components([.day,.month,.year], from: date) le

当我试图将评论保存到Firebase时,我的应用程序正在崩溃。此代码在Xcode 8更新之前运行良好:

    func saveNewComment(){

    //get date
    let date = Date()
    let calendar = Calendar.current
    let components = (calendar as NSCalendar).components([.day,.month,.year], from: date)

    let year = components.year
    let month = components.month
    let day = components.day

    //format month
    let dateFormatter: DateFormatter = DateFormatter()
    let months = dateFormatter.shortMonthSymbols
    let monthSymbol = months?[month!-1]
    let todaysDate = "\(day) \(monthSymbol),\(year)"

    //trim comment
    let comment = textView.text
    let trimmedComment = comment?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)

    //save new comment
    let commentRef = ref.child("Stores").child(getRef!).child("CommentArray").childByAutoId()

    commentRef.setValue([

        "Comment": trimmedComment,
        "Date": todaysDate

    ])

    self.delegate?.commentSubmitted(true)//delegate
    self.dismiss(animated: true, completion: nil)//dismiss view

}
显然,错误在于我试图使用“setValue”来设置那些键值对。你知道为什么会这样吗


提前感谢。

确保
getRef
是正确的节点名称,然后将todaysDate更改为

let todaysDate = "\(day!) \(monthSymbol!),\(year!)"

Firebase
不接受
可选类型作为值

let trimmedComment = comment?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) 
尝试用
打开
trimmedComment
todaydate

commentRef.setValue([
        "Comment": trimmedComment!,
        "Date": todaysDate!
 ])

您执行了什么更新?你得到了什么错误?getRef是什么?所以我更新了这个问题,我的错,我的意思是Xcode 8更新。另外,getRef只是您写下的对节点的引用。