encodePrettyPrinted

This commit is contained in:
spaced4ndy
2024-06-26 15:45:39 +04:00
parent 14f79df72f
commit 1d83140c1d
2 changed files with 9 additions and 2 deletions
@@ -50,7 +50,7 @@ struct ServersSummaryView: View {
private func shareButton() -> some View {
Button {
if let serversSummary = serversSummary {
showShareSheet(items: [encodeJSON(serversSummary)]) // TODO prettyJSON
showShareSheet(items: [encodePrettyPrinted(serversSummary)])
}
} label: {
Image(systemName: "square.and.arrow.up")
@@ -58,6 +58,13 @@ struct ServersSummaryView: View {
.disabled(serversSummary == nil)
}
public func encodePrettyPrinted<T: Encodable>(_ value: T) -> String {
let encoder = jsonEncoder
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(value)
return String(decoding: data, as: UTF8.self)
}
private func reloadButton() -> some View {
Button {
getServersSummary()
+1 -1
View File
@@ -10,7 +10,7 @@ import Foundation
import SwiftUI
public let jsonDecoder = getJSONDecoder()
let jsonEncoder = getJSONEncoder()
public let jsonEncoder = getJSONEncoder()
public enum ChatCommand {
case showActiveUser