Tusker/Pachyderm/Model/Emoji.swift

49 lines
1.5 KiB
Swift
Raw Normal View History

2018-09-11 14:52:21 +00:00
//
// Emoji.swift
// Pachyderm
//
// Created by Shadowfacts on 9/8/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
public class Emoji: Codable {
2019-02-10 02:12:31 +00:00
public let shortcode: String
public let url: URL
public let staticURL: URL
public let visibleInPicker: Bool
2018-09-11 14:52:21 +00:00
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.shortcode = try container.decode(String.self, forKey: .shortcode)
if let url = try? container.decode(URL.self, forKey: .url) {
self.url = url
} else {
let str = try container.decode(String.self, forKey: .url)
self.url = URL(string: str.replacingOccurrences(of: " ", with: "%20"))!
}
if let url = try? container.decode(URL.self, forKey: .staticURL) {
self.staticURL = url
} else {
let staticStr = try container.decode(String.self, forKey: .staticURL)
self.staticURL = URL(string: staticStr.replacingOccurrences(of: " ", with: "%20"))!
}
self.visibleInPicker = try container.decode(Bool.self, forKey: .visibleInPicker)
}
2018-09-11 14:52:21 +00:00
private enum CodingKeys: String, CodingKey {
case shortcode
case url
case staticURL = "static_url"
2019-02-10 02:12:31 +00:00
case visibleInPicker = "visible_in_picker"
2018-09-11 14:52:21 +00:00
}
}
extension Emoji: CustomDebugStringConvertible {
public var debugDescription: String {
return ":\(shortcode):"
}
}