We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
How can I parse the following Firebase Realtime Database JSON?
let firebaseRef = Database.database().reference() firebaseRef.observe(.value, with: { (snapshot) in
guard let value = snapshot.value as? [String: [String: [String: Any]]] else { return print("type wrong") } do { let model = try FirebaseDecoder().decode(AllData.self, from: Array(value.values)) print("model:", model) } catch let error { print("error", error) }
})
...and the following structs...
struct AllData: Codable { let news: News let events: Events let crew: Crew let artists: Artists } /////////////////////////////////// struct News: Codable { let news: NewsDetail }
struct NewsDetail: Codable { let title: String let subtitle: String } //////////////////////////////////// struct Artists: Codable { let artist: NewsDetail }
struct ArtistDetail: Codable { let name: String let image: String } ////////////////////////////////// struct Crew: Codable { let member: Member }
struct Member: Codable { let name: String let image: String } //////////////////////////////////// struct Events: Codable { let event: EventDetail } struct EventDetail: Codable { let title: String let subtitle: String let date: String }
Also with guard let value = snapshot.value as? [String:Any] gives me a typeMismatch(Swift.Dictionary<Swift.String, Any>) error. Can anyone help?
guard let value = snapshot.value as? [String:Any]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
How can I parse the following Firebase Realtime Database JSON?
let firebaseRef = Database.database().reference()
firebaseRef.observe(.value, with: { (snapshot) in
})
...and the following structs...
struct AllData: Codable {
let news: News
let events: Events
let crew: Crew
let artists: Artists
}
///////////////////////////////////
struct News: Codable {
let news: NewsDetail
}
struct NewsDetail: Codable {
let title: String
let subtitle: String
}
////////////////////////////////////
struct Artists: Codable {
let artist: NewsDetail
}
struct ArtistDetail: Codable {
let name: String
let image: String
}
//////////////////////////////////
struct Crew: Codable {
let member: Member
}
struct Member: Codable {
let name: String
let image: String
}
////////////////////////////////////
struct Events: Codable {
let event: EventDetail
}
struct EventDetail: Codable {
let title: String
let subtitle: String
let date: String
}
Also with
guard let value = snapshot.value as? [String:Any]
gives me a typeMismatch(Swift.Dictionary<Swift.String, Any>) error. Can anyone help?The text was updated successfully, but these errors were encountered: