encodable 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
6
Solved
I'm trying to get data by encode model which conforms to Encodable protocol. But it's failed to invoke func encode like code below:
// MARK: - Demo2
class TestClass2: NSObject, Encodable {
var x...
3
Solved
2
Solved
Recently i incorporated Codable in a project and to get a JSON object from a type conforming to Encodable i came up with this extension,
extension Encodable {
/// Converting object to postable J...
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
3
Imagine a data structure as follows, containing a value in contents that is an already encoded JSON fragment.
let partial = """
{ "foo": "Foo", "bar": 1 }
"""
struct Document {
let contents: Str...
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
Solved
I was looking for, in a struct, having a way of having a generic property where the type is defined at runtime like:
struct Dog {
let id: String
let value: ??
}
A simple use case where this ca...
Buffy asked 6/2, 2020 at 13:48
1
Solved
I have been playing around with Codable and reading and writing JSON from and to a file. Now I would like to write a custom Coder that can read and write iOS .strings files. Can anyone help me with...
2
I am just curious how can I encode a dictionary with String key and Encodable value into JSON.
For example:
let dict: [String: Encodable] = [
"Int": 1,
"Double": 3.14,
"Bool": false,
"String"...
Demilitarize asked 20/7, 2018 at 16:58
2
Solved
My app uses a server that returns JSON that looks like this:
{
"result":"OK",
"data":{
// Common to all URLs
"user": {
"name":"John Smith" // ETC...
},
// Different for each URL
"data_fo...
3
Solved
I am trying to use Swift 4 Decodable to parse an array that contains two different types of objects. The data looks something like this, with the included array being the one that contains both Mem...
2
Solved
I am trying to serialize a struct to a String using Swift 4's Encodable+JSONEncoder. The object can hold heterogenous values like String, Array, Date, Int etc.
The used approach works fine with t...
Felten asked 7/2, 2018 at 7:55
2
I want to encode Dictionary to json with JSONEncoder.
It seems like a Request, receive a dictionary as parameter and encode it to json as http body.
The code is looks like this:
let dict = ["name"...
Sonyasoo asked 31/1, 2018 at 14:6
2
Solved
I'm looking to store models objects in a Dictionary and would like to serialize the whole dictionary using JSONEncoder into data and subsequently into a string and save it.
The idea is to use Swif...
Eratosthenes asked 20/1, 2018 at 16:21
1
© 2022 - 2025 — McMap. All rights reserved.