Questions tagged [codable]

Use this tag only for questions directly pertaining to the Swift Codable protocol introduced in Swift 4.

Serialization / deserialization protocol composed of Encodable and Decodable protocols. Introduced in Swift 4.

References

1568 questions
-1
votes
1 answer

How to handle dynamic keys from a JSON response using jsonDecoder?

How do I handle this JSON and parse this JSON using decoder in Swift 4? I tried several times but failed. I don't understand how to handle this JSON format. [ { products: { id: 69, name: "test", des: "Hi this is a test", …
Avijit Mondal
  • 59
  • 1
  • 9
-1
votes
1 answer

JSON Parsing using Encodable class

I am trying to parse long response data : below is the code structure struct VizLog_UserProfile: Codable { let data: UserProfileData let app: App } struct UserProfileData: Codable { let roles: [String] let users: UserDetails …
Pradumna Patil
  • 2,180
  • 3
  • 17
  • 46
-1
votes
1 answer

How to manually decode json data in swift 4

How to manually decode [Album] and [Image] by keys ? I tried, but I can not. I do not know what the error is? Thank you ! My Json http://appscorporation.ga/api-user/test struct ProfileElement: Codable { let user: User let postImage: String …
-1
votes
1 answer

I can't change TabBarViewController when I Have an assync request

I can't change my view until my request and to find and fill my object. I tried to put my code assync with GCD. That don't work override func viewDidLoad() { …
Badr Filali
  • 279
  • 5
  • 21
-1
votes
1 answer

How can I init a struct from the values of a different struct

I have a user profile I am storing with a struct shaped like struct Profile: Codable { let company: String? let country: String? let createdDate: String? let dateOfBirth: String? let department: String? let email: String? …
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
-1
votes
1 answer

How to load that JSON on tableview?

I have problem with parse json to collectionview That is my JSON: { "statusCode": 200, "message": "Список курсов", "content": [ { "id": 1, "slug": "kurs-a1", "title": "Курс А1", "can_access": 1, …
Marshall
  • 141
  • 3
  • 9
-1
votes
1 answer

Ordered List With Core Data

I am working with a class which is both NSManagedObject and Codable. It's a Feed and it has multiple Albums. I want the ordered list of Albums but Core Data forces me to use Set instead, which is not ordered. I can use NSOrderedSet, but it doesn't…
Vandan Patel
  • 1,012
  • 1
  • 12
  • 23
-1
votes
2 answers

Handling unpredictable json response when working with swift codable

Sometimes my JSON response is like this { "products": [ { "pId": "3564225", "name": "Maxi Skirt", "slug": "maxi-skirt", "sku": "s-navy", "priority": 10, "images":…
imgroot
  • 131
  • 3
  • 11
-1
votes
2 answers

How to store Big Integer in Swift 4 Codable?

I am trying auto parsing an API with swift 4 codable. Some of the fields in the API are big integer which Codable does not support nor Swift 4.NSNumber is not supported by Codable and UInt64 is small for it to fit. I tried with a thrid party library…
Anuran Barman
  • 1,556
  • 2
  • 16
  • 31
-1
votes
2 answers

Parsing the JSON data with Codable

I have a JSON response that I am parsing with the help of codable models. Even though my models look good, I am getting the below error, FAILURE: typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath:…
-1
votes
2 answers

Why #Codable# not working in below code?

I have below code to test Codable protocol and JSONDecoder. import UIKit class ClassA: Codable { var age: Int = 1 } class ClassB: Codable { var ageInfo: ClassA? var name: String } let json4 = """ { "ageInfo": {}, "name":…
ZYiOS
  • 5,204
  • 3
  • 39
  • 45
-1
votes
4 answers

Codable: decoding by key

Suppose I have an API that returns this json: { "dogs": [{"name": "Bella"}, {"name": "Lucy"}], "cats": [{"name": "Oscar"}, {"name": "Coco"}] } And a model that looks like this: import Foundation public struct Animal: Codable { let name:…
etayluz
  • 15,920
  • 23
  • 106
  • 151
-1
votes
3 answers

How to parse JSON using swift 4

I am confusing to getting detail of fruit { "fruits": [ { "id": "1", "image": "https://cdn1.medicalnewstoday.com/content/images/headlines/271/271157/bananas.jpg", "name": "Banana" }, { "id": "2", "image":…
breath abel
  • 31
  • 1
  • 2
  • 9
-1
votes
1 answer

Parse JSON with variable keys

I'm trying to parse JSON with currency rates contains dynamic keys and a dynamic number of values. Output depends on input parameters, such as Base currency and several currencies to compare. Example of JSON: { "USD_AFN": 70.129997, "USD_AUD":…
Todd Page
  • 51
  • 5
-1
votes
2 answers

initialise Codable result with var

I need to initialise the result of JSONDecoder in a var object defined outside the API Call. apiService.GETAPI(url: apiStr, completion: {(success, result) in if(success) { let apiResponse = result.value as! NSDictionary …
Swati
  • 1,417
  • 1
  • 15
  • 35
1 2 3
99
100