Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Extension/CoreDataStack/Fields.swift

28 lines
531 B
Swift
Raw Normal View History

//
// Fields.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-5-25.
//
import Foundation
import MastodonSDK
2021-06-14 23:09:50 +02:00
protocol FieldContainer {
var fieldsData: Data? { get }
}
2021-06-14 23:09:50 +02:00
extension FieldContainer {
static func encode(fields: [Mastodon.Entity.Field]) -> Data? {
return try? JSONEncoder().encode(fields)
}
var fields: [Mastodon.Entity.Field]? {
let decoder = JSONDecoder()
return fieldsData.flatMap { try? decoder.decode([Mastodon.Entity.Field].self, from: $0) }
}
}