2021-05-27 07:56:55 +02:00
|
|
|
//
|
|
|
|
// 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 {
|
2021-05-27 07:56:55 +02:00
|
|
|
var fieldsData: Data? { get }
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:09:50 +02:00
|
|
|
extension FieldContainer {
|
2021-05-27 07:56:55 +02:00
|
|
|
|
|
|
|
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) }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|