Skip to content

Commit

Permalink
Another round of documentation and README updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
macblazer committed Oct 5, 2022
1 parent 3b389ae commit 81e4191
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies: [

## Usage
You will need to `import ManagedAppConfigLib` in each Swift file you wish to use it. You can choose
to use the property wrappers, or make use of the `ManagedAppConfig` class.
to use the read-only property wrappers, or make use of the `ManagedAppConfig` class for read and write access.

### SwiftUI Property Wrapper

Expand All @@ -51,8 +51,9 @@ Provides a read-only property that keeps itself current with any changes in the
This is useful for UIKit or AppKit code or simple Foundation code in models or cli tools.

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

### Simple functional use
Expand Down
11 changes: 11 additions & 0 deletions Sources/ManagedAppConfigLib/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,24 @@ import SwiftUI
// MARK: Initializers

/// Initializer for standard types
///
/// The `store` parameter is useful for unit tests or reading values from other suites.
/// - Parameters:
/// - defaultValue: The default value for the property if the AppConfig value is not set
/// - key: A key into the AppConfig dictionary
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
public init(wrappedValue defaultValue: Value, _ key: String, store: UserDefaults = UserDefaults.standard) {
self.key = key
self.defaults = store
self.defaultValue = defaultValue
}

/// Initializer for optional types; the default value is always nil
///
/// The `store` parameter is useful for unit tests or reading values from other suites.
/// - Parameters:
/// - key: A key into the AppConfig dictionary
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
public init(_ key: String, store: UserDefaults = UserDefaults.standard) where Value: ExpressibleByNilLiteral {
self.key = key
self.defaultValue = nil
Expand Down
11 changes: 11 additions & 0 deletions Sources/ManagedAppConfigLib/AppConfigPlain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ import Foundation
// MARK: - Initializers

/// Initializer for standard types
///
/// The `store` parameter is useful for unit tests or reading values from other suites.
/// - Parameters:
/// - defaultValue: The default value for the property if the AppConfig value is not set
/// - key: A key into the AppConfig dictionary
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
public init(wrappedValue defaultValue: Value, _ key: String, store: UserDefaults = UserDefaults.standard) {
self.defaultValue = defaultValue
listener.listenTo(store: store, key: key, defaultValue: defaultValue)
}

/// Initializer for optional types; their default value is always nil.
///
/// The `store` parameter is useful for unit tests or reading values from other suites.
/// - Parameters:
/// - key: A key into the AppConfig dictionary
/// - store: A `UserDefaults` object; defaults to the `.standard` object if not given.
public init(_ key: String, store: UserDefaults = UserDefaults.standard) where Value: ExpressibleByNilLiteral {
self.defaultValue = nil
listener.listenTo(store: store, key: key, defaultValue: nil)
Expand Down

0 comments on commit 81e4191

Please sign in to comment.