Swift Firebase查询数据按字符串数组

时间:2019-08-07 23:25:11

标签: swift firebase firebase-realtime-database

我一直在尝试通过firebase中的字符串数组过滤数据,以仅返回过滤后的值,但是当我尝试运行该函数时,应用程序崩溃了。这是应该做的方式吗? (如果数组为空,则不会调用该函数)

    func fetchFilteredActivities() {

    let ref = Database.database().reference().child("posts").queryOrdered(byChild: "category").queryEqual(toValue: filterList)
    ref.observe(.childAdded) { (snapshot) in

        guard let dictionary = snapshot.value as? [String: Any] else { return }

        guard let uid = dictionary["uid"] as? String else { return }

        guard let latitudeString = dictionary["latitude"] as? String else { return }
        guard let longitudeString = dictionary["longitude"] as? String else { return }

        let latitude = (latitudeString as NSString).doubleValue
        let longitude = (longitudeString as NSString).doubleValue

        Database.fetchUserWithUID(uid: uid, completion: { (user) in
            guard let dictionary = snapshot.value as? [String: Any] else { return }

            var post = Post(postId: snapshot.key, user: user, dictionary: dictionary)

            let postId = snapshot.key
            post.id = snapshot.key

            let coords = [CLLocation(latitude: latitude, longitude: longitude)]
            self.addAnnotation(post: post, title: post.category, subtitle: nil, coords: coords)
        })
    }
}

错误:     libc ++ abi.dylib:以类型为NSException的未捕获异常终止

0 个答案:

没有答案