Replies: 4 comments 1 reply
-
or was the plan to add it to the https://github.com/tgrapperon/swift-dependencies-additions/blob/main/Sources/UserDefaultsDependency/UserDefaults%2BSpecializations.swift for each type, similar to the |
Beta Was this translation helpful? Give feedback.
-
I added them in this branch. After using it a bit, I can create a PR. |
Beta Was this translation helpful? Give feedback.
-
Hey @atacan! That being said, and as I'm thinking about it again, it may be an omission. I think I forgot to get back to it once I implemented the corresponding functionality in Your changes are close to what I had in mind, but I'm wondering if we could not tidy a little the API by erasing the async sequences to |
Beta Was this translation helpful? Give feedback.
-
Good point about the types. Would you do it like this? private func existentialToConcrete<T>(_ asyncStreamAnySendable: AsyncStream<(any Sendable)?>)
-> AsyncStream<T?>
{
return AsyncStream<T?> { continuation in
Task {
for await value in asyncStreamAnySendable {
if let valueAsT = value as? T {
continuation.yield(valueAsT)
}
}
continuation.finish()
}
}
} then public func doubleValues(forKey key: String) -> AsyncStream<Double?> {
return existentialToConcrete(self._values(key, Double.self))
} |
Beta Was this translation helpful? Give feedback.
-
Hello, the
values
method in@Dependency(\.userDefaults)
is marked with@_spi(Internals)
.What is the way to loop on that async sequence?
Beta Was this translation helpful? Give feedback.
All reactions