Skip to content

Instantly share code, notes, and snippets.

@mortenbekditlevsen
Last active July 26, 2018 12:27
Show Gist options
  • Save mortenbekditlevsen/f92adb97ed5e41194475a8bfd352fbfa to your computer and use it in GitHub Desktop.
Save mortenbekditlevsen/f92adb97ed5e41194475a8bfd352fbfa to your computer and use it in GitHub Desktop.
// Instead of this ...
ref.observeSingleEvent(of: .value) { snapshot in
guard snapshot.exists() else {
/* HANDLE ERROR */
}
guard let value = snapshot.value else {
/* HANDLE ERROR */
}
guard let product = Product(usingMyCustomJSONConversion: value) else {
/* HANDLE ERROR */
}
}
// ... and this
let json: Any = product.myCustomJSONEncoding()
ref.setValue(json)
// ... instead do this ...
struct Product: Decodable { ... }
ref.observeSingleEvent(of: .value) { (result: DecodeResult<Product>) -> Void in
// Use result or handle error
}
// ... and this
try ref.setValue(product)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment