-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation lacks examples using Codable structs #2
Comments
Hi @djrobby, indeed the examples in the tests are quite succinct. For an example in a real Appstore App you could check out the code of this fully open-source App :https://github.com/EuroScorer/EuroScorer-iOS The particularity in this example is that Codable Models have been hidden behind a protocol for cleanness sake but you don't have to go to this level of abstraction if you don't want to. This technique enables us to hide away Firebase and the JSON api from the rest of the app. // Your Model (Simplified)
struct FirebaseSong: Song, Decodable {
let title: String
enum CodingKeys: String, CodingKey {
case title = "title"
}
}
// Tell Netwoking that its JSONDecodable (its empty since implementation is provided by default for Codables)
extension FirebaseSong: NetworkingJSONDecodable {}
// Perform your call
func fetchSongs() -> AnyPublisher<[Song], Error> {
get("/songs").map { (firebaseSongs: [FirebaseSong]) -> [Song] in
firebaseSongs.map { $0 as Song }
}.eraseToAnyPublisher()
} Let me know if that helps :) |
@djrobby Did that help? |
Yes, all set! Sorry, I forgot to mark the issue closed. done! |
I would really like to use your library in my current project but I'm having a real hard time getting POST, PUT and DELETE requests to work with Codable structs. Your documentation, including tests, only showcase rather simple examples that use strings as params. It would be nice if you could include addtional examples utilizing Codable structs. Thanks!
The text was updated successfully, but these errors were encountered: