Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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
Ios 如何使用firebase实现注释部分_Ios_Swift_Firebase - Fatal编程技术网

Ios 如何使用firebase实现注释部分

Ios 如何使用firebase实现注释部分,ios,swift,firebase,Ios,Swift,Firebase,我正在尝试使用firebase数据库对每个提要消息实现一个注释,但我不确定如何上传和提取注释。如果我的数据库看起来像是附件,我如何从firebase中提取数据 func uploadMessage(withContent content: String, withIcon icon: String, withColor color: String, withVotes votes: Int,sendComplete: @escaping (_ status: Bool) -> ()){

我正在尝试使用firebase数据库对每个提要消息实现一个注释,但我不确定如何上传和提取注释。如果我的数据库看起来像是附件,我如何从firebase中提取数据

func uploadMessage(withContent content: String, withIcon icon: String, withColor color: String, withVotes votes: Int,sendComplete: @escaping (_ status: Bool) -> ()){
        REF_FEEDMESSAGES.childByAutoId().updateChildValues(["content" : content, "color" : color, "icon" : icon)
        sendComplete(true)
    }

func getFeedMessages(handler: @escaping (_ feedMessages:[FeedMessages]) -> ()){
        var feedMessagesArray = [FeedMessages]()
        REF_FEEDMESSAGES.observeSingleEvent(of: .value) { (feedMessagesSnapshot) in
            guard let feedMessagesSnapshot = feedMessagesSnapshot.children.allObjects as? [DataSnapshot] else {return}

            for messages in feedMessagesSnapshot {
                let content = messages.childSnapshot(forPath: "content").value as? String ?? "Joe Flacco is an elite QB"
                let icon = messages.childSnapshot(forPath: "icon").value as? String ?? "none"
                let color = messages.childSnapshot(forPath: "color").value as? String ?? "bop"
                let votes = messages.childSnapshot(forPath: "votes").value as? Int ?? 0
                let messages = FeedMessages(content: content, color: color, icon: icon, votes: votes)
                feedMessagesArray.append(messages)
            }
            handler(feedMessagesArray)
        }
    }

您可以首先检查
REF\u ARTICLES
值,然后在
observeSingleEvent
的第一行添加一个打印项,并检查
articleMessageSnapshot.children.allObjects
是否有值,我不这么认为


可能您不需要检查子项,如果您添加firebase数据库树的图像,我们可以为您提供帮助。

在firebase回调中添加了打印语句??在该行处理程序(articleArray)执行打印(articleArray)之前,这是什么意思当我在getAllArticles函数中检查REF_ARTICLES时,它返回一个到firebase中我的数据库的链接
let article=articleArray\[indepath.row\]
这是什么?应该是
let article=articleArray[indexath.row]
在帖子的底部有一个firebase数据库的屏幕截图当我在getAllArticles函数中检查REF_ARTICLES时,它会将firebase中我的数据库的链接返回到数据库的根目录吗?你确定你在draftcalculator中吗?是的,我让它简单地工作了一下,但现在我得到了一个“无法将'NSNull'(0x1073ce850)类型的值强制转换为'NSString'(0x105ff22a8)”错误