Questions tagged [encodable]

Use this tag only for questions directly pertaining to the Swift standard Encodable protocol

It is the standardized protocol (defined by Swift standard library) for type that can encode itself to an external representation

References

104 questions
0
votes
1 answer

Codable variable inside Codable struct causes error

Please take a look at my code: No errors struct Person: Codable { var name: String var age: Double var birthday: Date var selectedItem: Car } struct Car: Codable { var companyName: String var creationDate:…
אורי orihpt
  • 2,358
  • 2
  • 16
  • 41
0
votes
1 answer

JSONencoder not saving new encoded json array (iOS)

I have a json file that looks like this (in a file called list.json) [ { "id": "C8B046E9-70F5-40D4-B19A-40B3E0E0877B", "name": "Dune", "author": "Frank Herbert", "page": "77", "total": "420", "image": "image1.jpg" }, { …
Arnav Motwani
  • 707
  • 7
  • 26
0
votes
1 answer

Array of subclass decoded as superclass

When I decode an array of the subclass(RegularCard), I get an array of the superclass (Card). The encoding is fine, I tested it and the encoding worked fine. But, when I decode, the function to decode the subclass(RegularCard) isn't called. My code…
Belal Elsiesy
  • 49
  • 1
  • 1
  • 3
0
votes
1 answer

Converting nested codable objects to dictionaries swift

I am currently using this extension which works fine for basic objects. I am having a hard time figuring out how to convert nested Codable objects to dictionaries with this call...thanks in advance! public extension Encodable { var dictionary:…
0
votes
1 answer

Swift Encodable parameter and Decodable response

I am migrating an old method I had using Alamofire where I have a function like this: protocol httpRequestSwiftDelegate { func httpRequestSwiftError(_ error: NSError, tag: Int) func httpRequestSwiftResponse(_ response: JSON, tag:…
JoeGalind
  • 3,545
  • 2
  • 29
  • 33
0
votes
2 answers

Issue in making a struct Codable

I have Application protocol with 2 variables. And I have component struct that has a variable, which confirms to Application protocol. I need to save this struct in disk . So I'm confirming it to Codable protocol. While doing so I'm getting an…
Jaffer Sheriff
  • 1,444
  • 13
  • 33
0
votes
0 answers

Instantiate a UIViewController using init(from decoder: Decoder)

I need to store ViewControllers created by the user into a json file and I need to recreate them on either the same device or a different device later on. The ViewControllers are available in the storyboard but I am not able to properly instantiate…
Fab
  • 1,468
  • 1
  • 16
  • 37
0
votes
0 answers

Calling default implementation of Codable encode function

Given the class: class ComplementApp: Codable { enum TypeCoder: String, Codable { case full, singleVal } var id_spring: String = "" var nombre: String = "" var typeCoder: TypeCoder = .full func encode(to encoder:…
0
votes
1 answer

How would I encode an NSSet in Swift Xcode?

I know how to do it when decoding which is stated below, but how would I go about it for encoding ? Just need to look at weatherDetail: NSSet I deleted the other containers as it's not necessary for the example. public class CurrentWeather:…
0
votes
0 answers

Type 'Cache' does not conform to protocol 'Encodable'

I have been following the guide found here for Caching in Swift. I am currently getting the error Type 'Cache' does not conform to protocol 'Encodable' This makes no sense to me as I have followed the guide to the letter, I have found a couple of…
Tim J
  • 1,211
  • 1
  • 14
  • 31
0
votes
0 answers

How to convert [JSON] in to data formate(Encode) so I can bind it with my model

I have data in the form of [JSON] array formate, I need to create model based on JSON and need to bind them I try to encode the [JSON] but app is crashing with error message Terminating app due to uncaught exception …
sham
  • 115
  • 9
0
votes
1 answer

How to map this heterogeneous object with the model in swift?

Okay, so I am stuck at decoding the last item of this particular json by this the model, "payload" is always nil, Inside this "payload" object I can make my own json structure, I am able to decode the "text" but when it comes to the last item which…
Shanu Singh
  • 365
  • 3
  • 16
0
votes
1 answer

Trying to make a class codable in Swift but it is not the correct format?

I am creating a class that conforms to codable. I have this: import Foundation class Attribute : Decodable { var number: Int16 var label: String? var comments: String? init(number:Int16, label:String?, comments:String?) { self.number…
Duck
  • 34,902
  • 47
  • 248
  • 470
0
votes
2 answers

Swift 4 decoding/encoding a generic data structure

I have a generic Queue data structure which utilizes an array as its list, I am having hard time making the queue conform to encodable and decodable. I have another class which uses the queue which also needs to be Codable but it cannot be coddle…
0
votes
3 answers

How to encode protocol property default implementation to dictionary

I want to make a dictionary from a encodable struct with a default implementation property. struct MyStruct: MyStructProtocol { var value: String } The struct implements a protocol. That protocol has two variables. One variable has a default…
SchmidtFx
  • 498
  • 4
  • 16