我试图允许用户将项目列表导出到便笺,但是由于某种原因,它仅导出第一个项目,而不是导出整个列表,就像我希望的那样。这是我的尝试...
guard let listId = list?.id else { return }
let ref = Database.database().reference().child("lists").child(listId).child("list-items")
ref.observe(.value) { (snapshot) in
guard let dict = snapshot.value as? [String: Any] else { return }
dict.forEach({ (key, value) in
let itemRef = Database.database().reference().child("items").child(key)
itemRef.observeSingleEvent(of: .value, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: Any] else { return }
guard let itemName = dictionary["item"] as? String else { return }
let activityController = UIActivityViewController(activityItems: [itemName], applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)
})
})
}