decodable Questions
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
2
Solved
I need to decode (Decodable protocol) an imprecise decimal value correctly, from this question I understand how to properly handle the Decimal instantiation, but how can I do this when decoding?
I...
Sailer asked 12/3, 2019 at 22:10
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...
3
Solved
So, I have a type which looks like this:
struct Identifier {
let string: String
}
extension Identifier: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.sing...
Longfellow asked 8/5, 2018 at 16:3
7
Here's my code:
class LoginUserResponse : Codable {
var result: String = ""
var data: LoginUserResponseData?
var mess: [String] = []
}
public class LoginUserResponseData : Codable {
var userI...
2
Solved
Is it possible to implement the Encodable and Decodable properties for UIColor
When I try to add a Decodable extension I get an error
extension UIColor : Decodable {
public required init(from de...
4
Solved
Found in Apple doc, that Codable protocol is composed of Encodable and Decodable. Thus,
Codable = Encodable & Decodable
Now, let's say I implemented below classes,
class X: Codable {
var n...
Gopak asked 12/3, 2020 at 10:30
1
Solved
I'm using a property wrapper to decode the strings "true" and "false" as Booleans. I also want to make the key optional. So if the key is missing from the JSON, it should be dec...
Especially asked 15/11, 2021 at 17:47
2
Solved
I was trying to connect my API data to view it in the cell but it seems that I can't get my response and it's always == nil
The code below describes the Country.SWIFT // Model.SWIFT // Response.SWI...
1
Solved
In a simple project at Github I am trying to download a list of JSON objects:
struct TopResponse: Codable {
let data: [Top]
}
struct Top: Codable /*, Identifiable */ {
let uid: Int
let elo: Int...
Janeejaneen asked 4/5, 2021 at 15:50
2
I have a generic REST request:
struct Request<T> {…}
The T is the return type of the request, for example:
struct Animal {…}
let animalRequest = Request<Animal>
let animal: Animal =...
3
Solved
I am using Codable protocol from Swift 4 first time, I am not able to understand use of decodeIfPresent from Decodable.
/// Decodes a value of the given type for the given key, if present.
///
//...
4
Solved
I am attempting to decode a JSON response from a third-party API which contains nested/child JSON that has been base64 encoded.
Contrived Example JSON
{
"id": 1234,
"attributes&quo...
2
Solved
I'm working with CoreData and JSON parsing with Decodable following this and encountered an error at the end of the initializer saying 'self.init' isn't called on all paths before returning from in...
2
Solved
I am writing a program using Swift 4 and Xcode 9.2. I have faced difficulties with writing encodable class (exactly class, not struct). When I am trying to inherit one class from another, JSONEncod...
Haunted asked 13/1, 2018 at 8:28
2
I’m using Swift to try and decode JSON:API-formatted JSON results. The JSON I’m trying to parse has a shape like this:
{
"data": {
"type": "video",
"id": ...
3
Solved
Within the app, we have two types of Stickers, String and Bitmap. Each sticker pack could contain both types. This is how I declare the models:
// Mark: - Models
protocol Sticker: Codable {
}
pu...
4
Solved
I had issue with JSON parsing in Swift 4.2. Here is the following code which shown runtime error.
My Json data is as follow which i got from server.
{
code: 406,
message: "Email Address alread...
3
I have the following data structure:
{
"type": "foo"
"data": { /* foo object */ }
}
Here's my class for decoding it:
final public class UntypedObject: Decodable {
public var data: Data
e...
4
Solved
Let's say I have the following decodable struct as an example illustrating what I'm trying to do:
struct Object: Decodable {
var id: String
var name: String
}
and this JSON:
[
{
"id"...
2
Solved
I'm refactoring some projects where I'd previously used third-party JSON parsers and I've encountered a goofy site that returns a boolean as a string.
This is the relevant snippet from the JSON re...
1
Solved
Is there a way to keep Swift's default implementation for a Decodable class with only Decodable objects but one exception?
So for example if I have a struct/class like that:
struct MyDecodable: De...
4
With API I'm working with, I have a case where 1 API Endpoint can return completely different responses, based on if the call was successful or not.
In case of success, API Endpoint returns an Arra...
Leucippus asked 10/11, 2019 at 20:43
3
Solved
I know the basic concept of class and struct but which is more effective to create models for API to fetch data and tell me with pros and cons.
Previously i don't use optional for models. Instead...
1 Next >
© 2022 - 2025 — McMap. All rights reserved.