From 9446541d15f1b4c7026db4ac875962fa242703d2 Mon Sep 17 00:00:00 2001 From: mmt9497 Date: Sun, 2 Jul 2023 00:48:01 +0530 Subject: [PATCH] Make entities public --- Sources/JSONViewer/JSONNode.swift | 28 +++++++++++------------- Sources/JSONViewer/JSONNodeView.swift | 4 ++-- Sources/JSONViewer/StringExtension.swift | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Sources/JSONViewer/JSONNode.swift b/Sources/JSONViewer/JSONNode.swift index 8562e21..201c55a 100644 --- a/Sources/JSONViewer/JSONNode.swift +++ b/Sources/JSONViewer/JSONNode.swift @@ -7,43 +7,41 @@ import Foundation -enum JSONNodeType { +public enum JSONNodeType { case object case array case other } -var str = "".jsonNode - -struct JSONNode: Identifiable, Hashable, Sequence { +public struct JSONNode: Identifiable, Hashable, Sequence { - static func == (lhs: JSONNode, rhs: JSONNode) -> Bool { + public static func == (lhs: JSONNode, rhs: JSONNode) -> Bool { return lhs.id == rhs.id } - func hash(into hasher: inout Hasher) { + public func hash(into hasher: inout Hasher) { hasher.combine(id) } - init(key: String, value: String, children: [JSONNode]) { + public init(key: String, value: String, children: [JSONNode]) { self.key = key self.value = value self.children = children } - let id = UUID() - var key: String - let value: String - var children: [JSONNode] - var type: JSONNodeType = .other + public let id = UUID() + public var key: String + public let value: String + public var children: [JSONNode] + public var type: JSONNodeType = .other - var isExpandable: Bool { + public var isExpandable: Bool { return !children.isEmpty } - typealias Iterator = Array.Iterator + public typealias Iterator = Array.Iterator - func makeIterator() -> Iterator { + public func makeIterator() -> Iterator { return children.makeIterator() } } diff --git a/Sources/JSONViewer/JSONNodeView.swift b/Sources/JSONViewer/JSONNodeView.swift index d53a4bc..d0b9b8a 100644 --- a/Sources/JSONViewer/JSONNodeView.swift +++ b/Sources/JSONViewer/JSONNodeView.swift @@ -7,11 +7,11 @@ import SwiftUI -struct JSONNodeView: View { +public struct JSONNodeView: View { var node: JSONNode var level: Int @State var expanded: [String: Bool] - var body: some View { + public var body: some View { VStack { if node.isExpandable { VStack(alignment: .trailing) { diff --git a/Sources/JSONViewer/StringExtension.swift b/Sources/JSONViewer/StringExtension.swift index 448bf2b..caf26b9 100644 --- a/Sources/JSONViewer/StringExtension.swift +++ b/Sources/JSONViewer/StringExtension.swift @@ -7,7 +7,7 @@ import Foundation -extension String { +public extension String { var jsonNode: JSONNode? { if let jsonData = self.data(using: .utf8) { do {