From 1d83140c1dbccf593216ba6fdd86be0781676171 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:45:39 +0400 Subject: [PATCH] encodePrettyPrinted --- apps/ios/Shared/Views/ChatList/ServersSummaryView.swift | 9 ++++++++- apps/ios/SimpleXChat/APITypes.swift | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/Views/ChatList/ServersSummaryView.swift b/apps/ios/Shared/Views/ChatList/ServersSummaryView.swift index 10aa4b184d..a6a353c068 100644 --- a/apps/ios/Shared/Views/ChatList/ServersSummaryView.swift +++ b/apps/ios/Shared/Views/ChatList/ServersSummaryView.swift @@ -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(_ 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() diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index c430e38a21..9dacedb31b 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -10,7 +10,7 @@ import Foundation import SwiftUI public let jsonDecoder = getJSONDecoder() -let jsonEncoder = getJSONEncoder() +public let jsonEncoder = getJSONEncoder() public enum ChatCommand { case showActiveUser