-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable syncing from local if its default after iCloud.add
#185
Conversation
Sources/Defaults/Defaults.swift
Outdated
/** | ||
Check whether the stored value is the default value. | ||
*/ | ||
public func isDefaultValue() -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a property and I don't think it should be public as it wouldn't work for non-equatable values.
We can instead add a version of this publicly:
Defaults/Sources/Defaults/SwiftUI.swift
Lines 162 to 167 in bf71746
extension Default where Value: Equatable { | |
/** | |
Indicates whether the value is the same as the default value. | |
*/ | |
public var isDefaultValue: Bool { wrappedValue == defaultValue } | |
} |
public static func add(_ keys: [Defaults.Keys]) { | ||
synchronizer.add(keys) | ||
public static func add<each Value: Defaults.Serializable>(_ keys: repeat Defaults.Key<each Value>) { | ||
repeat synchronizer.add(each keys) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested and would require Swift 6, but maybe:
public static func add<each Value: Defaults.Serializable>(_ keys: repeat [Defaults.Key<each Value>]) {
for key in repeat each keys {
add(key)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, will add a TODO
for it first!
Looks great. Thanks for fixing this 👍 |
Description
This PR fixes #172.
By default,
Defaults
will create a sync task that automatically detects the data source using timestamps. However, this might cause an issue if the device is newly installed, as it might accidentally push the default value to iCloud. It's also unnecessary to publish the default value to iCloud upon initialization, since all devices should already have that value.Implementation
Added a new function
isDefaultValue
forDefaults.Key<Value>
.To detect if the locally stored value is a default value, I had to change
Defaults.iCloud.add
to use a generic packed parameter.Question
This change introduces a new issue: we cannot support
Defaults.iCloud.add
with an array ofDefaults.Key<Value>
due to the lack of variadic parameter support. Is there any way to resolve this?