在我的应用中,我试图在收藏夹视图中获取要检索的帖子的缩略图(正在运行)。但是,然后我想向该图像添加一个子对象,其中包含第二个图像的图像路径以及将在另一个集合视图中检索的标签。但是创建帖子后,我想不出一种方法使孩子成为第一张图片。
这是我的代码:
@IBAction func postPressed(_ sender: Any) {
AppDelegate.instance().showActivityIndicator()
let uid = Auth.auth().currentUser!.uid
let ref = Database.database().reference()
let storage = Storage.storage().reference(forURL: "gs://mobile-d9fcd.appspot.com")
let key = ref.child("posts").childByAutoId().key
let imageRef = storage.child("posts").child(uid).child("\(key).jpg")
let data = UIImageJPEGRepresentation(self.previewImage.image!, 0.6)
let uploadTask = imageRef.putData(data!, metadata: nil) { (metadata, error) in
if error != nil {
print(error!.localizedDescription)
AppDelegate.instance().dismissActivityIndicator()
return
}
imageRef.downloadURL(completion: { (url, error) in
if let url = url {
let feed = ["userID" : uid,
"pathToImage" : url.absoluteString,
"likes" : 0,
"author" : Auth.auth().currentUser!.displayName!,
"postID" : key] as [String : Any]
let postFeed = ["\(key)" : feed]
ref.child("posts").updateChildValues(postFeed)
AppDelegate.instance().dismissActivityIndicator()
self.picker.dismiss(animated: true, completion: nil)
}
})
}
uploadTask.resume()
}
以下是我想要的示例(“ subposts”是显示第二张图片的图片的路径):