Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created October 2, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikdenic/9a017874ae1ab10e0cf895517d08cba1 to your computer and use it in GitHub Desktop.
Save vikdenic/9a017874ae1ab10e0cf895517d08cba1 to your computer and use it in GitHub Desktop.
//
// 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