Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jamf/managedappconfiglib

Makes Managed AppConfig on iOS, tvOS, and macOS easier to work with.
https://github.com/jamf/managedappconfiglib

appconfig cocoapods ios ios-development macos macos-development swift swift-package-manager swiftpackage swiftui tvos tvos-development

Last synced: 2 months ago
JSON representation

Makes Managed AppConfig on iOS, tvOS, and macOS easier to work with.

Awesome Lists containing this project

README

        

# ManagedAppConfigLib

## Overview
The purpose of ManagedAppConfigLib is to make it much easier to work with Apple's
[Managed App Configuration](https://developer.apple.com/library/content/samplecode/sc2279/Introduction/Intro.html)
by providing a class that manages access to it, as well as some property wrappers for modern Swift usage.

Managed App Configuration is supported by Apple on iOS 7+, macOS 11+, and tvOS 10.2+.

## Installation

### CocoaPods

Install via [Cocoapods](https://guides.cocoapods.org/using/getting-started.html) by adding the following to your Podfile under your desired targets:

```ruby
pod 'ManagedAppConfigLib'
```

### Swift Package Manager

Install with [Swift Package Manager](https://github.com/apple/swift-package-manager) by adding the following to your `Package.swift` file:

```swift
dependencies: [
.package(url: "https://github.com/jamf/ManagedAppConfigLib")
],
```

## Learn More

[The documentation](https://jamf.github.io/ManagedAppConfigLib/documentation/managedappconfiglib/)
for this package was generated by [DocC](https://developer.apple.com/documentation/docc)
using [publish_docs.yml](https://github.com/jamf/ManagedAppConfigLib/blob/main/.github/workflows/publish_docs.yml) with GitHub Actions.

## Basic Usage
You will need to `import ManagedAppConfigLib` in each Swift file you wish to use it.

### SwiftUI Property Wrapper

Functions much like the [@AppStorage](https://developer.apple.com/documentation/swiftui/appstorage)
property wrapper built in to SwiftUI. Provides a type-safe read-only property that keeps itself
current with any changes in the AppConfig value, and causes a SwiftUI redraw when it's value changes.

```swift
// If AppConfig "title" doesn't exist or is not a string, will have the value "Default title".
@AppConfig("title") var title = "Default title"
// If AppConfig "featureEnabled" doesn't exist or is not a boolean, will have the value `false`.
@AppConfig("featureEnabled") var isEnabled: Bool = false
// If AppConfig "orgColor" doesn't exist or is not a string, this will be nil.
@AppConfig("orgColor") var organizationHexColor: String?
```

### Non-SwiftUI Property Wrapper

Functions much like the `@AppConfig` property wrapper except that it does not require SwiftUI.
Provides a read-only property that keeps itself current with any changes in the AppConfig value.
This is useful for UIKit or AppKit code or simple Foundation code in models or cli tools.

```swift
@AppConfigPlain("title") var title = "Default title"
@AppConfigPlain("featureEnabled") var isEnabled: Bool = false
@AppConfigPlain("orgColor") var organizationHexColor: String?
```

### Simple functional use

* Retrieve a Managed App Configuration value
```swift
if let deviceId = ManagedAppConfig.shared.getConfigValue(forKey: "deviceId") as? String {
print(deviceId)
}
```

* Register a closure to be executed when Managed App Configuration changes
```swift
let myClosure = { (configDict: [String: Any?]) -> Void in
print("Managed App Configuration changed")
}
ManagedAppConfig.shared.addAppConfigChangedHook(myClosure)

```

* Place a value into Managed App Feedback
```swift
let numberOfErrors = 0
ManagedAppConfig.shared.updateValue(numberOfErrors, forKey: "errorCount")
```

## Contributing

This repository now requires verified signed commits. You can find out more about
[signing commits on GitHub Docs](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits).