Skip to content

Commit

Permalink
Rename WrappedDefault --> FoilDefaultStorage (#94)
Browse files Browse the repository at this point in the history
Closes #73.
  • Loading branch information
jessesquires committed Jan 11, 2024
1 parent 58a6979 commit 8f47696
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 60 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ This release closes the [5.0.0 milestone](https://github.com/jessesquires/Foil/m

- The `UserDefaultsSerializable` protocol has changed. Previously, it declared the initializer `init(storedValue:)`. It is now failable: `init?(storedValue:)`. This change was necessary to accommodate `Codable` types (see below). ([#92](https://github.com/jessesquires/Foil/issues/92), [@jessesquires](https://github.com/jessesquires))

- Both property wrappers **have been renamed**. `@WrappedDefault` is now `@FoilDefaultStorage` and `@WrappedDefaultOptional` is now `@FoilDefaultStorageOptional`. To migrate, you can simply find-and-replace these names. Nothing else has changed. ([#73](https://github.com/jessesquires/Foil/issues/73), [#94](https://github.com/jessesquires/Foil/issues/94), [@jessesquires](https://github.com/jessesquires))

### New

- Support for `Codable` types. (Please don't abuse this. See the docs.) ([#72](https://github.com/jessesquires/Foil/issues/72), [#92](https://github.com/jessesquires/Foil/issues/92), [@jessesquires](https://github.com/jessesquires))

- Added [privacy manifest](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files) for iOS 17. ([@jessesquires](https://github.com/jessesquires))

### Changed
Expand Down
12 changes: 6 additions & 6 deletions Example/ExampleApp/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ enum AppSettingsKey: String, CaseIterable {
final class AppSettings: NSObject, ObservableObject {
static let shared = AppSettings()

@WrappedDefault(.flagEnabled)
@FoilDefaultStorage(.flagEnabled)
@objc dynamic var flagEnabled = true {
willSet {
objectWillChange.send()
}
}

@WrappedDefault(.totalCount)
@FoilDefaultStorage(.totalCount)
var totalCount = 0 {
willSet {
objectWillChange.send()
}
}

@WrappedDefaultOptional(.timestamp)
@FoilDefaultStorageOptional(.timestamp)
var timestamp: Date? {
willSet {
objectWillChange.send()
}
}

@WrappedDefaultOptional(.option)
@FoilDefaultStorageOptional(.option)
var option: String? {
willSet {
objectWillChange.send()
Expand All @@ -60,13 +60,13 @@ final class AppSettings: NSObject, ObservableObject {
}
}

extension WrappedDefault {
extension FoilDefaultStorage {
init(wrappedValue: T, _ key: AppSettingsKey) {
self.init(wrappedValue: wrappedValue, key: key.rawValue)
}
}

extension WrappedDefaultOptional {
extension FoilDefaultStorageOptional {
init(_ key: AppSettingsKey) {
self.init(key: key.rawValue)
}
Expand Down
24 changes: 12 additions & 12 deletions Foil.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
0BA3823F2602C498005D7B2E /* IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA3823E2602C498005D7B2E /* IntegrationTests.swift */; };
0BA382422602C4D2005D7B2E /* TestSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA382372602C1A7005D7B2E /* TestSettings.swift */; };
0BC99BA8266C27AE009B8CD4 /* ObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC99BA7266C27AE009B8CD4 /* ObservationTests.swift */; };
0BEEA2B22603F8390035387F /* WrappedDefaultOptional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BEEA2B12603F8390035387F /* WrappedDefaultOptional.swift */; };
0BEEA2B22603F8390035387F /* FoilDefaultStorageOptional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BEEA2B12603F8390035387F /* FoilDefaultStorageOptional.swift */; };
0BEEA2BC260403560035387F /* UserDefaults+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BEEA2BB260403560035387F /* UserDefaults+Extensions.swift */; };
0BF54A8A25BF589E008484F8 /* Foil.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0BF54A8025BF589E008484F8 /* Foil.framework */; };
0BF54A8F25BF589E008484F8 /* WrappedDefaultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF54A8E25BF589E008484F8 /* WrappedDefaultTests.swift */; };
0BF54A8F25BF589E008484F8 /* PropertyWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF54A8E25BF589E008484F8 /* PropertyWrapperTests.swift */; };
0BF54A9D25BF58B1008484F8 /* UserDefaults+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF54A9C25BF58B1008484F8 /* UserDefaults+Extensions.swift */; };
0BF5FD9025C14A7D0003B078 /* WrappedDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF5FD8F25C14A7D0003B078 /* WrappedDefault.swift */; };
0BF5FD9025C14A7D0003B078 /* FoilDefaultStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF5FD8F25C14A7D0003B078 /* FoilDefaultStorage.swift */; };
0BF5FD9625C14A960003B078 /* UserDefaultsSerializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BF5FD9525C14A960003B078 /* UserDefaultsSerializable.swift */; };
1CC00F2428DAB1FC00EC2C63 /* ObserverTrampoline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CC00F2328DAB1FC00EC2C63 /* ObserverTrampoline.swift */; };
/* End PBXBuildFile section */
Expand All @@ -35,13 +35,13 @@
0BA382372602C1A7005D7B2E /* TestSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSettings.swift; sourceTree = "<group>"; };
0BA3823E2602C498005D7B2E /* IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationTests.swift; sourceTree = "<group>"; };
0BC99BA7266C27AE009B8CD4 /* ObservationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservationTests.swift; sourceTree = "<group>"; };
0BEEA2B12603F8390035387F /* WrappedDefaultOptional.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedDefaultOptional.swift; sourceTree = "<group>"; };
0BEEA2B12603F8390035387F /* FoilDefaultStorageOptional.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoilDefaultStorageOptional.swift; sourceTree = "<group>"; };
0BEEA2BB260403560035387F /* UserDefaults+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extensions.swift"; sourceTree = "<group>"; };
0BF54A8025BF589E008484F8 /* Foil.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Foil.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0BF54A8925BF589E008484F8 /* FoilTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FoilTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
0BF54A8E25BF589E008484F8 /* WrappedDefaultTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedDefaultTests.swift; sourceTree = "<group>"; };
0BF54A8E25BF589E008484F8 /* PropertyWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrapperTests.swift; sourceTree = "<group>"; };
0BF54A9C25BF58B1008484F8 /* UserDefaults+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extensions.swift"; sourceTree = "<group>"; };
0BF5FD8F25C14A7D0003B078 /* WrappedDefault.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedDefault.swift; sourceTree = "<group>"; };
0BF5FD8F25C14A7D0003B078 /* FoilDefaultStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoilDefaultStorage.swift; sourceTree = "<group>"; };
0BF5FD9525C14A960003B078 /* UserDefaultsSerializable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsSerializable.swift; sourceTree = "<group>"; };
1CC00F2328DAB1FC00EC2C63 /* ObserverTrampoline.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObserverTrampoline.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -86,12 +86,12 @@
0BF54A8225BF589E008484F8 /* Sources */ = {
isa = PBXGroup;
children = (
0BF5FD8F25C14A7D0003B078 /* FoilDefaultStorage.swift */,
0BEEA2B12603F8390035387F /* FoilDefaultStorageOptional.swift */,
1CC00F2328DAB1FC00EC2C63 /* ObserverTrampoline.swift */,
0B315D1E2B4E051C000F5034 /* PrivacyInfo.xcprivacy */,
0BF54A9C25BF58B1008484F8 /* UserDefaults+Extensions.swift */,
0BF5FD9525C14A960003B078 /* UserDefaultsSerializable.swift */,
0BF5FD8F25C14A7D0003B078 /* WrappedDefault.swift */,
0BEEA2B12603F8390035387F /* WrappedDefaultOptional.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand All @@ -101,9 +101,9 @@
children = (
0BA3823E2602C498005D7B2E /* IntegrationTests.swift */,
0BC99BA7266C27AE009B8CD4 /* ObservationTests.swift */,
0BF54A8E25BF589E008484F8 /* PropertyWrapperTests.swift */,
0BA382372602C1A7005D7B2E /* TestSettings.swift */,
0BEEA2BB260403560035387F /* UserDefaults+Extensions.swift */,
0BF54A8E25BF589E008484F8 /* WrappedDefaultTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -243,8 +243,8 @@
files = (
0BF5FD9625C14A960003B078 /* UserDefaultsSerializable.swift in Sources */,
1CC00F2428DAB1FC00EC2C63 /* ObserverTrampoline.swift in Sources */,
0BEEA2B22603F8390035387F /* WrappedDefaultOptional.swift in Sources */,
0BF5FD9025C14A7D0003B078 /* WrappedDefault.swift in Sources */,
0BEEA2B22603F8390035387F /* FoilDefaultStorageOptional.swift in Sources */,
0BF5FD9025C14A7D0003B078 /* FoilDefaultStorage.swift in Sources */,
0BF54A9D25BF58B1008484F8 /* UserDefaults+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -255,7 +255,7 @@
files = (
0BC99BA8266C27AE009B8CD4 /* ObservationTests.swift in Sources */,
0BA382422602C4D2005D7B2E /* TestSettings.swift in Sources */,
0BF54A8F25BF589E008484F8 /* WrappedDefaultTests.swift in Sources */,
0BF54A8F25BF589E008484F8 /* PropertyWrapperTests.swift in Sources */,
0BA3823F2602C498005D7B2E /* IntegrationTests.swift in Sources */,
0BEEA2BC260403560035387F /* UserDefaults+Extensions.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
/// A property wrapper that uses `UserDefaults` as a backing store,
/// whose `wrappedValue` is non-optional and registers a **non-optional default value**.
@propertyWrapper
public struct WrappedDefault<T: UserDefaultsSerializable> {
public struct FoilDefaultStorage<T: UserDefaultsSerializable> {
private let _userDefaults: UserDefaults
private let _publisher: CurrentValueSubject<T, Never>
private let _observer: ObserverTrampoline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
/// A property wrapper that uses `UserDefaults` as a backing store,
/// whose `wrappedValue` is optional and **does not provide default value**.
@propertyWrapper
public struct WrappedDefaultOptional<T: UserDefaultsSerializable> {
public struct FoilDefaultStorageOptional<T: UserDefaultsSerializable> {
private let _userDefaults: UserDefaults
private let _publisher: CurrentValueSubject<T?, Never>
private let _observer: ObserverTrampoline
Expand Down
6 changes: 3 additions & 3 deletions Sources/UserDefaultsSerializable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ extension Data: UserDefaultsSerializable {
}
}

/// :nodoc:
// Note: yes, compactMap will remove nil values, but collections of optionals are not valid plist types.
// If a value is nil, it simply gets removed from UserDefaults.
// Thus, this will never happen. For example, you cannot store [Int?], only [Int].
/// :nodoc:
extension Array: UserDefaultsSerializable where Element: UserDefaultsSerializable {
public var storedValue: [Element.StoredValue] {
self.compactMap { $0.storedValue }
Expand All @@ -139,10 +139,10 @@ extension Array: UserDefaultsSerializable where Element: UserDefaultsSerializabl
}
}

/// :nodoc:
// Note: yes, compactMap will remove nil values, but collections of optionals are not valid plist types.
// If a value is nil, it simply gets removed from UserDefaults.
// Thus, this will never happen. For example, you cannot store [Int?], only [Int].
/// :nodoc:
extension Set: UserDefaultsSerializable where Element: UserDefaultsSerializable {
public var storedValue: [Element.StoredValue] {
self.map { $0.storedValue }
Expand All @@ -153,10 +153,10 @@ extension Set: UserDefaultsSerializable where Element: UserDefaultsSerializable
}
}

/// :nodoc:
// Note: yes, compactMap will remove nil values, but collections of optionals are not valid plist types.
// If a value is nil, it simply gets removed from UserDefaults.
// Thus, this will never happen. For example, you cannot store [Int?], only [Int].
/// :nodoc:
extension Dictionary: UserDefaultsSerializable where Key == String, Value: UserDefaultsSerializable {
public var storedValue: [String: Value.StoredValue] {
self.compactMapValues { $0.storedValue }
Expand Down
Loading

0 comments on commit 8f47696

Please sign in to comment.