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

28 lines
531 B
Swift

//
// Fields.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-5-25.
//
import Foundation
import MastodonSDK
protocol FieldContainer {
var fieldsData: Data? { get }
}
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) }
}
}