Skip to content

Commit 3fcabd1

Browse files
authored
Merge pull request #5 from macblazer/improve-documentation
Improve documentation
2 parents 309318f + fc1a600 commit 3fcabd1

File tree

17 files changed

+352
-60
lines changed

17 files changed

+352
-60
lines changed

.github/workflows/publish_docs.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Publish Docs
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'main'
8+
9+
# Kill any previous run still executing
10+
concurrency:
11+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build_docs:
16+
name: Build and Archive Docs
17+
runs-on: macos-12
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Generate docs
23+
run: |
24+
swift package \
25+
--allow-writing-to-directory github-pages \
26+
generate-documentation \
27+
--target ManagedAppConfigLib \
28+
--disable-indexing \
29+
--transform-for-static-hosting \
30+
--hosting-base-path ManagedAppConfigLib/ \
31+
--output-path github-pages
32+
33+
- name: Upload docs archive
34+
uses: actions/upload-pages-artifact@main
35+
with:
36+
path: github-pages
37+
38+
deploy:
39+
name: Deploy Docs
40+
needs: build_docs
41+
42+
permissions:
43+
pages: write
44+
id-token: write
45+
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deployment.outputs.page_url }}
49+
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Deploy
53+
id: deployment
54+
uses: actions/deploy-pages@v1

.github/workflows/run_tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run unit tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
paths:
9+
- '**.swift'
10+
11+
# Kill any previous run still executing
12+
concurrency:
13+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
14+
cancel-in-progress: true
15+
16+
jobs:
17+
spm_tests:
18+
name: Run package tests
19+
runs-on: macos-12
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Unit Test
25+
run: swift test -v

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
xcuserdata
22
.DS_Store
33
.swiftpm
4+
.build
5+
Package.resolved

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## [1.1.0] - 2022-10-28
88
### Added
99
- Property wrapper for SwiftUI and non-SwiftUI to make grabbing AppConfig values very simple.
10+
- Additional documentation for use with DocC.
11+
- Add unit tests and run them through GitHub Actions when swift files change.
12+
- Publish docs from main branch in GitHub Actions.
1013

1114
### Changed
1215
- Updated documentation for `ManagedAppConfig` class.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2017 JAMF Software LLC
1+
Copyright 2022 Jamf Open Source Community
22

33
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:
44

ManagedAppConfigLib.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Pod::Spec.new do |s|
22
s.name = "ManagedAppConfigLib"
3-
s.version = "1.0.0"
4-
s.summary = "A facade that simplifies working with Managed App Configuration and Feedback."
3+
s.version = "1.1.0"
4+
s.summary = "Simplify working with Managed App Configuration and Feedback."
55

66
s.description = <<-DESC
7-
The purpose of ManagedAppConfigLib is to make it that much easier to work with Apple's [Managed App Configuration](https://developer.apple.com/library/content/samplecode/sc2279/Introduction/Intro.html) by providing a few convenience methods.
7+
The purpose of ManagedAppConfigLib is to make it easier to work with Apple's [Managed App Configuration](https://developer.apple.com/library/content/samplecode/sc2279/Introduction/Intro.html) by providing a couple property wrappers and an object-based approach.
88
DESC
99

1010
s.homepage = "https://appconfig.org/"
1111
s.license = { :type => "MIT", :file => "LICENSE" }
12-
s.author = { "James Felton" => "james.felton@jamf.com" }
12+
s.author = "Kyle Hammond", "James Felton"
1313

1414
s.swift_versions = "5.1"
1515
s.platform = :ios, "8.0"

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.6
22
import PackageDescription
33

44
let package = Package(
@@ -11,6 +11,9 @@ let package = Package(
1111
products: [
1212
.library(name: "ManagedAppConfigLib", targets: ["ManagedAppConfigLib"])
1313
],
14+
dependencies: [
15+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
16+
],
1417
targets: [
1518
.target(name: "ManagedAppConfigLib"),
1619
.testTarget(name: "ManagedAppConfigLibTests", dependencies: ["ManagedAppConfigLib"])

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ dependencies: [
2727
],
2828
```
2929

30-
## Usage
31-
You will need to `import ManagedAppConfigLib` in each Swift file you wish to use it. You can choose
32-
to use the read-only property wrappers, or make use of the `ManagedAppConfig` class for read and write access.
30+
## Complete Documentation
31+
32+
[The documentation](https://jamf.github.io/ManagedAppConfigLib/documentation/managedappconfiglib/)
33+
for this package was generated by [DocC](https://developer.apple.com/documentation/docc)
34+
from GitHub Actions. Take a look at the workflow file
35+
[publish_docs.yml](https://github.com/jamf/ManagedAppConfigLib/blob/main/.github/workflows/publish_docs.yml)
36+
for more details.
37+
38+
## Basic Usage
39+
You will need to `import ManagedAppConfigLib` in each Swift file you wish to use it.
3340

3441
### SwiftUI Property Wrapper
3542

@@ -60,26 +67,24 @@ This is useful for UIKit or AppKit code or simple Foundation code in models or c
6067

6168
### Simple functional use
6269

63-
* Retrieve a value set by MDM from the Managed App Configuration:
70+
* Retrieve a Managed App Configuration value
6471
```swift
6572
if let deviceId = ManagedAppConfig.shared.getConfigValue(forKey: "deviceId") as? String {
6673
print(deviceId)
6774
}
6875
```
6976

70-
* Register a closure to be executed when the managed app configuration dictionary is changed:
77+
* Register a closure to be executed when Managed App Configuration changes
7178
```swift
7279
let myClosure = { (configDict: [String: Any?]) -> Void in
73-
print("managed app configuration changed")
80+
print("Managed App Configuration changed")
7481
}
7582
ManagedAppConfig.shared.addAppConfigChangedHook(myClosure)
7683

7784
```
7885

79-
* Place a value into the managed app feedback dictionary:
86+
* Place a value into Managed App Feedback
8087
```swift
81-
let exampleKey = "errorCount"
82-
let exampleValue = 0
83-
ManagedAppConfig.shared.updateValue(exampleValue, forKey: exampleKey)
84-
88+
let numberOfErrors = 0
89+
ManagedAppConfig.shared.updateValue(numberOfErrors, forKey: "errorCount")
8590
```

Sources/ManagedAppConfigLib/AppConfig.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
import Foundation
77
import SwiftUI
88

9-
/// A property wrapper type that reflects a value from Managed App Config (via `UserDefaults`) and
10-
/// invalidates a SwiftUI view on a change in value in that Managed App Config.
9+
/// A read-only property wrapper type that reflects a value from Managed App Configuration (via `UserDefaults`) and
10+
/// invalidates a SwiftUI view on a change in value in that Managed App Configuration.
11+
///
12+
/// Create an app config value in a SwiftUI `View`, `App`, or `Scene` by applying the `@AppConfig` attribute to a property
13+
/// declaration.
14+
///
15+
/// When the Managed App Config value changes, SwiftUI updates the parts of any view that depend on those properties.
1116
@available(macOS 11, iOS 13.0, tvOS 13.0, *)
1217
@propertyWrapper public struct AppConfig<Value>: DynamicProperty {
1318
// Very simple listener that observes AppConfig changes, and has a local copy of the AppConfig's value.
@@ -45,7 +50,7 @@ import SwiftUI
4550
private let defaults: UserDefaults
4651
private let defaultValue: Value
4752

48-
/// The value from AppConfig or the defaultValue provided to the initializer.
53+
/// The value from Managed App Configuration or the `defaultValue` provided to the initializer.
4954
public var wrappedValue: Value {
5055
core.value ?? defaultValue
5156
}
@@ -59,12 +64,12 @@ import SwiftUI
5964

6065
// MARK: Initializers
6166

62-
/// Initializer for standard types
67+
/// Initializer for standard types.
6368
///
6469
/// The `store` parameter is useful for unit tests or reading values from other suites.
6570
/// - Parameters:
66-
/// - defaultValue: The default value for the property if the AppConfig value is not set
67-
/// - key: A key into the AppConfig dictionary
71+
/// - defaultValue: The default value for the property if the Managed App Configuration value is not set.
72+
/// - key: A key into the Managed App Configuration dictionary.
6873
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
6974
public init(wrappedValue defaultValue: Value, _ key: String, store: UserDefaults = UserDefaults.standard) {
7075
self.key = key
@@ -76,7 +81,7 @@ import SwiftUI
7681
///
7782
/// The `store` parameter is useful for unit tests or reading values from other suites.
7883
/// - Parameters:
79-
/// - key: A key into the AppConfig dictionary
84+
/// - key: A key into the Managed App Configuration dictionary.
8085
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
8186
public init(_ key: String, store: UserDefaults = UserDefaults.standard) where Value: ExpressibleByNilLiteral {
8287
self.key = key

Sources/ManagedAppConfigLib/AppConfigPlain.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55

66
import Foundation
77

8-
/// A property wrapper type that can be used outside of SwiftUI that reflects a value from Managed App Config
9-
/// (via `UserDefaults`) and keeps itself up to date with changes in value in that Managed App Config.
8+
/// A read-only property wrapper type that reflects a value from Managed App Configuration
9+
/// (via `UserDefaults`) and keeps itself up to date with changes in value in that Managed App Configuration.
10+
///
11+
/// Can be used outside of SwiftUI.
12+
///
13+
/// If used in a SwiftUI view, does **not** trigger a SwiftUI view redraw when the
14+
/// Managed App Configuration value changes. See ``AppConfig`` if you want a SwiftUI view to redraw on update
15+
/// of a Managed App Configuration value.
1016
@available(macOS 11, iOS 7.0, tvOS 10.2, *)
1117
@propertyWrapper public struct AppConfigPlain<Value> {
1218
// Very simple listener that observes AppConfig changes, and updates it's internal copy of the value as needed.
@@ -35,19 +41,19 @@ import Foundation
3541
private var listener = Listener<Value>()
3642
private let defaultValue: Value
3743

38-
/// The value from AppConfig or the defaultValue provided to the initializer.
44+
/// The value from Managed App Configuration or the defaultValue provided to the initializer.
3945
public var wrappedValue: Value {
4046
listener.value ?? defaultValue
4147
}
4248

4349
// MARK: - Initializers
4450

45-
/// Initializer for standard types
51+
/// Initializer for standard types.
4652
///
4753
/// The `store` parameter is useful for unit tests or reading values from other suites.
4854
/// - Parameters:
49-
/// - defaultValue: The default value for the property if the AppConfig value is not set
50-
/// - key: A key into the AppConfig dictionary
55+
/// - defaultValue: The default value for the property if the Managed App Configuration value is not set.
56+
/// - key: A key into the Managed App Configuration dictionary.
5157
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
5258
public init(wrappedValue defaultValue: Value, _ key: String, store: UserDefaults = UserDefaults.standard) {
5359
self.defaultValue = defaultValue
@@ -58,7 +64,7 @@ import Foundation
5864
///
5965
/// The `store` parameter is useful for unit tests or reading values from other suites.
6066
/// - Parameters:
61-
/// - key: A key into the AppConfig dictionary
67+
/// - key: A key into the Managed App Configuration dictionary.
6268
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
6369
public init(_ key: String, store: UserDefaults = UserDefaults.standard) where Value: ExpressibleByNilLiteral {
6470
self.defaultValue = nil

0 commit comments

Comments
 (0)