Swiftpack.co - jamf/ManagedAppConfigLib as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jamf.
jamf/ManagedAppConfigLib 1.1.2
Makes Managed AppConfig on iOS, tvOS, and macOS easier to work with.
⭐️ 34
🕓 36 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/jamf/ManagedAppConfigLib.git", from: "1.1.2")

ManagedAppConfigLib

Overview

The purpose of ManagedAppConfigLib is to make it much easier to work with Apple's Managed App Configuration 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 by adding the following to your Podfile under your desired targets:

pod 'ManagedAppConfigLib'

Swift Package Manager

Install with Swift Package Manager by adding the following to your Package.swift file:

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

Learn More

The documentation for this package was generated by DocC using 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 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.

// 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.

@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
if let deviceId = ManagedAppConfig.shared.getConfigValue(forKey: "deviceId") as? String {
    print(deviceId)
}
  • Register a closure to be executed when Managed App Configuration changes
let myClosure = { (configDict: [String: Any?]) -> Void in
    print("Managed App Configuration changed")
}
ManagedAppConfig.shared.addAppConfigChangedHook(myClosure)

  • Place a value into Managed App Feedback
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.

GitHub

link
Stars: 34
Last commit: 36 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Updated CocoaPods release
36 weeks ago

v1.1.1 was not released to the CocoaPods ecosystem due to issues supporting iOS 8 with Xcode 14.3.

This release fixes that problem and future proofs the code a little bit more for the eventual release of Swift 6.

Full Changelog: https://github.com/jamf/ManagedAppConfigLib/compare/1.1.1...1.1.2

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics