diff --git a/Sources/LicenseList/Library.swift b/Sources/LicenseList/Library.swift index 0a58916..99bf54b 100644 --- a/Sources/LicenseList/Library.swift +++ b/Sources/LicenseList/Library.swift @@ -1,11 +1,21 @@ import Foundation +/// A structure that contains information about a library that the project depends on. public struct Library: Identifiable, Hashable { + /// The unique identifier. public let id: UUID = .init() + /// The library name. public let name: String + /// The repository url. public let url: URL? + /// The license body. public let licenseBody: String + /// Creates a library with the specified name, repository url, and license body. + /// - Parameters: + /// - name: The library name. + /// - url: The repository url. + /// - licenseBody: The license body. public init(name: String, url: String, licenseBody: String) { self.name = name self.url = URL(string: url) @@ -14,6 +24,7 @@ public struct Library: Identifiable, Hashable { } extension Library { + /// The libraries automatically collected by the internal plug-in. public static var libraries: [Library] { return SPP.libraries.compactMap { info -> Library? in guard let name = info["name"], diff --git a/Sources/LicenseList/LicenseListView.swift b/Sources/LicenseList/LicenseListView.swift index f63ff26..bb3baa5 100644 --- a/Sources/LicenseList/LicenseListView.swift +++ b/Sources/LicenseList/LicenseListView.swift @@ -1,15 +1,21 @@ import SwiftUI +/// A view that presents license views in a list format. public struct LicenseListView: View { @Environment(\.licenseViewStyle) private var licenseViewStyle: LicenseViewStyle let libraries = Library.libraries let navigationHandler: ((Library) -> Void)? + /// Creates new license list view. + /// - Parameters: + /// - navigationHandler: The closure to navigate for the given ``Library``. + /// This is used when controlling navigation using a UINavigationController. public init(navigationHandler: ((Library) -> Void)? = nil) { self.navigationHandler = navigationHandler } + /// The content and behavior of the license list view. public var body: some View { List { ForEach(libraries) { library in diff --git a/Sources/LicenseList/LicenseListViewController.swift b/Sources/LicenseList/LicenseListViewController.swift index a0fb00c..971d385 100644 --- a/Sources/LicenseList/LicenseListViewController.swift +++ b/Sources/LicenseList/LicenseListViewController.swift @@ -1,9 +1,17 @@ import UIKit import SwiftUI +/// A view controller that specializes in managing a license list view. +/// +/// A view controller implements the following behavior: +/// - Displays a list of libraries that your project depends on via Swift Package Manager. +/// - The list is sorted alphabetically by library name. +/// - Selecting each library will open a details page where you can view the license body. public class LicenseListViewController: UIViewController { + /// The style that specifies behavior of license views. public var licenseViewStyle: LicenseViewStyle = .plain + /// Creates a license list view controller. public init() { super.init(nibName: nil, bundle: nil) } @@ -12,6 +20,9 @@ public class LicenseListViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + /// Called after the controller's view is loaded into memory. + /// + /// The view controller embeds ``LicenseListView`` as a child view using UIHostingController. public override func viewDidLoad() { super.viewDidLoad() let licenseListView = LicenseListView() { [weak self] library in diff --git a/Sources/LicenseList/LicenseView.swift b/Sources/LicenseList/LicenseView.swift index 57a670b..58556f2 100644 --- a/Sources/LicenseList/LicenseView.swift +++ b/Sources/LicenseList/LicenseView.swift @@ -1,5 +1,6 @@ import SwiftUI +/// A view that displays license body. public struct LicenseView: View { @State private var attributedLicenseBody = AttributedString(stringLiteral: "") @@ -8,10 +9,14 @@ public struct LicenseView: View { private let library: Library + /// Creates new license list view with the specified library. + /// - Parameters: + /// - library: The library to use in this view. public init(library: Library) { self.library = library } + /// The content and behavior of the license view. public var body: some View { ScrollView { Text(attributedLicenseBody) diff --git a/Sources/LicenseList/LicenseViewStyle.swift b/Sources/LicenseList/LicenseViewStyle.swift index 8febc89..93fac34 100644 --- a/Sources/LicenseList/LicenseViewStyle.swift +++ b/Sources/LicenseList/LicenseViewStyle.swift @@ -1,7 +1,10 @@ import SwiftUI +/// A style for license views. public enum LicenseViewStyle { + /// The style used to display just the license body. case plain + /// The style used to display the license body and repository anchor link. case withRepositoryAnchorLink } diff --git a/Sources/LicenseList/View+Extensions.swift b/Sources/LicenseList/View+Extensions.swift index f0d30fb..4bcbe01 100644 --- a/Sources/LicenseList/View+Extensions.swift +++ b/Sources/LicenseList/View+Extensions.swift @@ -12,7 +12,7 @@ extension View { } } } - + func _licenseViewStyle(_ style: LicenseViewStyle, action: @escaping () -> Void) -> some View { Group { switch style { @@ -23,7 +23,8 @@ extension View { } } } - + + /// Sets the style for license views within this view. public func licenseViewStyle(_ style: LicenseViewStyle) -> some View { self.environment(\.licenseViewStyle, style) }