forked from contentstack/contentstack-utils-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGQLEmbededAsset.swift
More file actions
48 lines (37 loc) · 1.42 KB
/
GQLEmbededAsset.swift
File metadata and controls
48 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// GQLEmbededAsset.swift
// ContentstackUtils
//
// Created by Uttam Ukkoji on 20/07/21.
//
internal class GQLEmbededAsset: Decodable, EmbeddedAsset {
static var contentTypeUid: String = "sys_asset"
var uid: String
var url: String
var title: String
var filename: String
var contentTypeUID: String
public var fields: [String: Any]?
public enum FieldKeys: String, CodingKey {
case title, uid, url, filename
case contentTypeUID = "content_type_uid"
}
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: FieldKeys.self)
uid = ""
url = try container.decodeIfPresent(String.self, forKey: .url) ?? ""
title = try container.decodeIfPresent(String.self, forKey: .title) ?? ""
filename = try container.decodeIfPresent(String.self, forKey: .filename) ?? ""
contentTypeUID = ""
let containerFields = try decoder.container(keyedBy: JSONCodingKeys.self)
fields = try containerFields.decode(Dictionary<String, Any>.self)
if let allfields = fields, let system = allfields["system"] as? [String: Any] {
if let val = system["uid"] as? String {
uid = val
}
if let contentType = system["content_type_uid"] as? String {
contentTypeUID = contentType
}
}
}
}