I used this tutorial to add data to Firebase. It works perfectly. It also works offline thanks to the snapshots and persistence.
I also added images to Firebase storage from the this link. This also works, but not for persistence. I have tried to replicate the snapshot from the data (first tutorial) to do this, but FIRStorageReference does not have snapshot options as far as I can see. How can I do this?
import Foundation
import Firebase
import FirebaseStorage
struct MenuItemImage {
let image: NSData
let ref: FIRStorageReference?
let key: String
init(image: NSData, key: String = "") {
self.key = key
self.image = image
self.ref = nil
}
init(snapshot: FIRDataSnapshot) { // this should be something like FIRStoreSnapshot
key = snapshot.key
let snapshotValue = snapshot.value as! [String: AnyObject]
image = snapshotValue["image"] as! NSData
ref = snapshot.ref // errors as cannot assign value of tupe FIRDatabaseReference to type FIRStorageReference
}
func toAnyObject() -> Any {
return [
"image": image
]
}
}