codable Questions
4
I am trying to map my data to Model.
Where I am using Firestore snapshot listener, to get data.
here, I am getting data and mapping to "User" model that;
do{
let user = try User(dictionary: temp...
1
How can I convert Codable struct to a JSON Data object and keep the order of the struct variables? I know that Dictionary is not ordered and that JSONEncoder and JSONSerialization.data accepts only...
4
Solved
In trying to serialize an array of float3 objects with the basic JSONEncoder, it's revealed that float3 does not conform to the Codable protocol, so this cannot be done.
I tried to write a basic e...
Folberth asked 29/1, 2018 at 1:45
6
Say I have the following code:
import Foundation
let jsonData = """
[
{"firstname": "Tom", "lastname": "Smith", "age": {"realage": "28"}},
{"firstname": "Bob", "lastname": "Smith", "age": {"fak...
3
Solved
I'm trying to implement Codable for a class which contains a NSAttributedString, but I get errors at compile time:
try container.encode(str, forKey: .str)
error ambiguous reference to member '...
Vertical asked 16/3, 2018 at 4:46
4
Solved
I have defined a enum like this:
enum ClubLevel: Int, Codable {
case golden = 1, silver, bronze
}
in my struct I have an optional property of type ClubLevel and when I decode this property in i...
12
Solved
3
Solved
I'm starting to rewrite an application and I want to use Swift 4 Codable protocol to automatically convert json string to Objects and Structs.
Sometimes, specially at the beginning of coding, I en...
6
Solved
I have an API that will sometimes return a specific key value (in this case id) in the JSON as an Int and other times it will return that same key value as a String. How do I use codable to parse t...
5
Solved
So I have an API route that returns a JSON array of objects. For example:
[
{"firstname": "Tom", "lastname": "Smith", "age": 31},
{"firstname": "Bob", "lastname": "Smith", "age": 28}
]
I'm try...
8
Solved
Here is my JSON
{
"id": 1,
"user": {
"user_name": "Tester",
"real_info": {
"full_name":"Jon Doe"
}
},
"reviews_count": [
{
"count": 4
}
]
}
Here is the structure I want it saved to (...
4
Solved
I have the following Swift structs
struct Session: Encodable {
let sessionId: String
}
struct Person: Encodable {
let name: String
let age: Int
}
let person = Person(name: "Jan", age: 36)
let ...
6
Solved
My data structure has an enum as a key, I would expect the below to decode automatically. Is this a bug or some configuration issue?
import Foundation
enum AnEnum: String, Codable {
case enumVal...
3
Solved
private func createWeatherObjectWith(json: Data, x:Any.Type ,completion: @escaping (_ data: Any?, _ error: Error?) -> Void) {
do {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = ....
3
I have the Animal protocol with 2 structs that conform to it and a Farm struct which stores a list of Animals. Then, I make them all conform to Codable to store it in a file, but it throws the erro...
13
Solved
8
Solved
Swift 4 added the new Codable protocol. When I use JSONDecoder it seems to require all the non-optional properties of my Codable class to have keys in the JSON or it throws an error.
Making every ...
4
Solved
I want to encode an optional field with Swift's JSONEncoderusing a struct that conforms to the Encodable protocol.
The default setting is that JSONEncoder uses the encodeIfPresent method, which me...
6
I have a Codable class:
class Task: Codable {
var name: String
}
When I try to instantiate it:
let newTask = Task()
allTasks.append(newTask)
It gives me error:
Missing argument for parame...
5
I'm using Codable for my WebRequest response which is returning some predefined string or number. So, I'm using Enums for those. But when some unexpected value arrive to Response at that my Codable...
4
Solved
I have an EmailVerificationStatus enum with an associated type of String that conforms to the Codable protocol:
enum EmailVerificationStatus: String, Codable {
case unverified
case verified
}
...
3
Solved
I want to upload an image file to the backend server, using certain URL endpoint. I can easily do that using Alamofire's upload request as multipartFormData. However I want to get rid of Alamofire ...
Parve asked 4/10, 2019 at 11:49
4
Solved
I am trying to encode a struct
struct Configuration : Encodable, Decodable {
private enum CodingKeys : String, CodingKey {
case title = "title"
case contents = "contents"
}
var title : String...
Rehnberg asked 5/8, 2018 at 18:9
12
Solved
Why am I getting a "Type 'Bookmark' does not conform to protocol 'Decodable'" error message?
class Bookmark: Codable {
weak var publication: Publication?
var indexPath: [Int]
var locationInText...
5
Solved
I'm trying to find the best way to Encode/Decode an array of structs conforming to a swift protocol using the new JSONDecoder/Encoder in Swift 4.
I made up a little example to illustrate the probl...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.