Skip to content

Commit

Permalink
feat: adds the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhermawan committed Dec 4, 2023
1 parent a315876 commit 3b32e6b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build-test:
runs-on: macos-latest
runs-on: macos-13

steps:
- uses: actions/checkout@v3
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Docs

on:
release:
types: [published]

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
runs-on: macos-13

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- uses: actions/checkout@v3
- uses: actions/configure-pages@v3

- name: Select Xcode 15
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app/Contents/Developer

- name: Build docs
run: swift package --allow-writing-to-directory ./docs generate-documentation --target AppInfo --disable-indexing --output-path ./docs --transform-for-static-hosting --hosting-base-path AppInfo

- uses: actions/upload-pages-artifact@v2
with:
path: "docs"

- uses: actions/deploy-pages@v2
id: deployment
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
/docs
/.build
/Packages
xcuserdata/
Expand Down
23 changes: 23 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin.git",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
}
],
"version" : 2
}
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ let package = Package(
name: "AppInfo",
targets: ["AppInfo"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.3.0"))
],
targets: [
.target(
name: "AppInfo"),
Expand Down
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

![Test coverage](https://img.shields.io/codecov/c/github/kevinhermawan/AppInfo)

A simple Swift utility to fetch application metadata from `Info.plist`.

## Overview

The `AppInfo` struct provides static properties and functions that allow you to fetch common details from your application's `Info.plist` file, such as the app's name, version, build number, and bundle identifier. Additionally, it provides a generic function to retrieve any custom key-value pair from the `Info.plist`.
A utility for accessing application metadata from `Info.plist`.

## Installation

Expand All @@ -26,21 +22,32 @@ Alternatively, in Xcode:
4. Choose the version you want to add. You probably want to add the latest version.
5. Click `Add Package`.

## Usage

```swift
import AppInfo

// Fetching predefined details
print(AppInfo.name ?? "Unknown App Name")
print(AppInfo.version ?? "Unknown Version")
print(AppInfo.buildNumber ?? "Unknown Build Number")
print(AppInfo.bundleIdentifier ?? "Unknown Bundle Identifier")
## Documentation

// Fetching a custom key from Info.plist
print(AppInfo.value(for: "YourCustomKey") ?? "Unknown Value")
```
You can find the documentation here: [https://kevinhermawan.github.io/AppInfo/documentation/appinfo](https://kevinhermawan.github.io/AppInfo/documentation/appinfo)

## License

[MIT License](/LICENSE)
```
MIT License
Copyright (c) 2023 Kevin Hermawan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
24 changes: 24 additions & 0 deletions Sources/AppInfo/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,49 @@

import Foundation

/// A structure that provides convenient access to information about the current application.
///
/// This structure encapsulates functionality for retrieving various pieces of information about the application from its bundle. These include the app's name, version number, build number, and bundle identifier. Additionally, it offers a method to fetch custom values from the info dictionary.
public struct AppInfo {
/// The main bundle of the application.
///
/// This internal static property is set to the main bundle of the application. It is used within the `AppInfo` struct to access various properties from the bundle's info dictionary.
internal static var bundle: Bundle = .main

/// The name of the application.
///
/// This computed property returns the application's name as specified in the `CFBundleName` key of the bundle's info dictionary. The return type is an optional string, reflecting that the bundle might not contain this key.
public static var name: String? {
bundle.infoDictionary?["CFBundleName"] as? String
}

/// The version number of the application.
///
/// This computed property returns the version number of the application. The version number is defined in the `CFBundleShortVersionString` key of the bundle's info dictionary. It returns an optional string, as the info dictionary might not have this key.
public static var version: String? {
bundle.infoDictionary?["CFBundleShortVersionString"] as? String
}

/// The build number of the application.
///
/// This computed property retrieves the build number of the application from the `CFBundleVersion` key in the bundle's info dictionary. It returns an optional string since the key may not be present in the dictionary.
public static var buildNumber: String? {
bundle.infoDictionary?["CFBundleVersion"] as? String
}

/// The bundle identifier of the application.
///
/// This computed property returns the bundle identifier of the application. It is an optional string, as there might be scenarios where the bundle identifier is not set.
public static var bundleIdentifier: String? {
bundle.bundleIdentifier
}

/// Retrieves a specific value from the application's info dictionary.
///
/// This method allows for fetching custom values from the application's info dictionary using their respective keys. It's particularly useful for accessing custom metadata defined in the app's bundle.
///
/// - Parameter key: A string representing the key for the desired value in the info dictionary.
/// - Returns: An optional string containing the value associated with the specified key, or nil if the key does not exist.
public static func value(for key: String) -> String? {
bundle.infoDictionary?[key] as? String
}
Expand Down

0 comments on commit 3b32e6b

Please sign in to comment.