Created
October 2, 2017 19:30
-
-
Save vikdenic/9a017874ae1ab10e0cf895517d08cba1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TopicsToHelpWith.swift | |
// SpokinModel | |
// | |
// Created by Kevin McQuown on 9/28/17. | |
// Copyright © 2017 Spokin. All rights reserved. | |
// | |
// swiftlint:disable force_try | |
import Foundation | |
public class DiscoveryTopic: Codable { | |
public let id: String | |
public let displayName: String | |
let imageAssetName: String | |
public var isSelected = false | |
private let imageAssets: [[String: String]] | |
private enum CodingKeys: String, CodingKey { | |
case id | |
case displayName = "displayValue" | |
case imageAssetName | |
case imageAssets | |
} | |
required public init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: CodingKeys.self) | |
id = try! container.decode(String.self, forKey: .id) | |
displayName = try! container.decode(String.self, forKey: .displayName) | |
imageAssets = try! container.decode([[String: String]].self, forKey: .imageAssets) | |
imageAssetName = URL(fileURLWithPath: imageAssets.first!["selected"]!).lastPathComponent.components(separatedBy: ".").first! | |
} | |
} | |
public class DiscoveryTopicCategory: Codable { | |
let id: String | |
public let displayName: String | |
public let topics: [DiscoveryTopic] | |
public var isAllSelected = false | |
private enum CodingKeys: String, CodingKey { | |
case id = "hexValue" | |
case displayName = "displayValue" | |
case topics | |
} | |
} | |
public class TopicRoot: Codable { | |
let data: [DiscoveryTopicCategory] | |
let definition: String | |
} | |
public class DiscoveryTopics { | |
public static let shared = DiscoveryTopics() | |
let root: TopicRoot | |
public let categories: [DiscoveryTopicCategory] | |
public init() { | |
let bundle = BuildConfiguration.bundle() | |
let path = bundle.path(forResource: "DiscoveryTopics", ofType: "plist")! | |
let data = try! Data(contentsOf:URL(fileURLWithPath: path)) | |
let decoder = PropertyListDecoder() | |
self.root = try! decoder.decode(TopicRoot.self, from: data) | |
self.categories = self.root.data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment