Last active
July 26, 2018 12:27
-
-
Save mortenbekditlevsen/f92adb97ed5e41194475a8bfd352fbfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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