This package parses your Settings.bundle for licenses generated with the LicensePlist package by Masayuki Ono.
You can also provide static licenses by passing LicenseItem to the view model or create your own LicenseLoader implementation.
Some of the most popular license terms can be retrieved using the License enum.
Install LicenseUI with Swift Package Manager:
dependencies: [
.package(name: "LicenseUI", url: "https://github.com/lambdadigamma/swift-license-ui", .upToNextMajor(from: "1.0.0")),
]You can render the default user interface shipped with this package by using the LicenseList and its corresponding view model LicensesViewModel .
The license terms are displayed in a LicenseDetailView.
Be aware that the default implementation is based on a SwiftUI
Listand needs to be embedded in a navigation context.
To render licenses in your Settings.bundle generated with the LicensePlist package,
you can display the list like that:
LicensesList(viewModel: LicensesViewModel())To render a static list of licenses you can either use the StaticLicenseLoader or the convenience initializer:
LicensesList(viewModel: LicensesViewModel(licenses: licenses))Or use a custom loader:
LicensesList(viewModel: LicensesViewModel(loader: CustomLicenseLoader()))To render a custom user interface you can still use the LicensesViewModel to power it.
The view model publishes the array licenses which you can use in your view.
Just make sure to call viewModel.load() at a given time to execute the provided loader.
Licenses are being loaded by loaders conforming to the LicenseLoader protocol.
Loaders only need to implement a load method which returns an array of LicenseItem.
The default StaticLicenseLoader implementation looks like this:
public class StaticLicenseLoader: LicenseLoader {
public let licenses: [LicenseItem]
public init(licenses: [LicenseItem] = []) {
self.licenses = licenses
}
public func load() -> [LicenseItem] {
return licenses
}
}- Implement
Settings.bundleparsing - Implement a static LicenseLoader
- Implement rendering license list and license terms
- Add the most popular licenses
- Support more localizations
Please see CHANGELOG.md for more information what has changed recently.
Contributions are always welcome!
swift-license-ui is available under the MIT license. See the LICENSE.md file for more info.
