Я не могу вытащить изображения, которые я ранее загрузил в FireBase.Я пытаюсь войти, и тогда загруженные изображения будут отображаться в виде таблицы.Однако я получаю сообщение об ошибке потока 1, и оно сообщает мне
'Предоставленная корзина: memestreamios.appspot.comMemes не соответствует корзине хранения текущего экземпляра: memestreamios.appspot.com'
ниже мой код
class Post {
// Variables
var caption : String!
var imageDownloadURL : String!
private var image : UIImage!
// Initialization of the variables
init(image : UIImage, caption : String) {
self.caption = caption
self.image = image
}
// Snapshot the data
init(snapshot : DataSnapshot) {
let json = JSON(snapshot.value ?? "")
self.caption = json["caption"].stringValue
self.imageDownloadURL = json["imageDownloadURL"].stringValue
}
// Function to save the newPost
func save() {
// 1 - Create a new Database Reference
let newPostRef = Database.database().reference().child("posts").childByAutoId()
let newPostKey = newPostRef.key
// Convert image into data
if let imageData = self.image.jpegData(compressionQuality: 0.6) {
// 2 - Create a new Strage Reference
let imageStorageRef = Storage.storage().reference().child("Memes")
let newImageRef = imageStorageRef.child(newPostKey)
// 3 - Save the image to the storage URL
newImageRef.putData(imageData).observe(.success, handler: { (snapshot) in
// 4 - Save the post caption & download URL
self.imageDownloadURL = snapshot.metadata?.downloadURL()?.absoluteString
let newDictionary = [
"imageDownloadURL" : self.imageDownloadURL,
"caption" : self.caption
]
newPostRef.setValue(newDictionary)
})
}
}
}
//Table view page
class PhotoTableViewCell: UITableViewCell {
// variables
var post : Post! {
didSet {
self.updateUI()
}
}
@IBOutlet weak var postImageView: UIImageView!
@IBOutlet weak var captionLabel: UILabel!
@IBOutlet weak var shadowBackgroundView: UIView!
func updateUI() {
// Set shadow background view
shadowBackgroundView.layer.shadowPath = UIBezierPath(rect: shadowBackgroundView.bounds).cgPath
shadowBackgroundView.layer.shadowColor = UIColor.black.cgColor
shadowBackgroundView.layer.shadowOpacity = 0.1
shadowBackgroundView.layer.shadowOffset = CGSize(width: 2, height: 2)
shadowBackgroundView.layer.shadowRadius = 2
shadowBackgroundView.layer.masksToBounds = false
shadowBackgroundView.layer.cornerRadius = 3.0
// Caption
self.captionLabel.text = post.caption
// Download the post photo from Firebase
if let imageDownloadURL = post.imageDownloadURL {
// 1 - Create the Storage Reference
let imageStorageRef = Storage.storage().reference(forURL: imageDownloadURL)
// 2 - Observe method to download the data
imageStorageRef.getData(maxSize: 2 * 1024 * 1024, completion: { [weak self](data, error) in
if let error = error {
print("*** ERROR DOWNLOAD IMAGE : \(error)")
} else {
// Success
if let imageData = data {
// 3 - Put the image in imageview
DispatchQueue.main.async {
let image = UIImage(data: imageData)
self?.postImageView.image = image
}
}
}
})
}
}
}