Closed sindresorhus closed 1 year ago
I think we might have three ways to do it.
Mark Defaults.Key
initializer as throws
:
try
when initialize Defaults.Key
.Add an assertion in Defaults.Key
initializer:
try
.Mark KVO
related function(ex. Defaults.observe
) as throws
:
try
.Only 2. is really feasible.
The question is, do assertions work when they are in a package and you build your app in debug mode.
Actually, a better solution could be to show a warning in Xcode using this hack: https://github.com/pointfreeco/swift-composable-architecture/blob/main/Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift
Actually, a better solution could be to show a warning in Xcode using this hack: pointfreeco/swift-composable-architecture@main/Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift
This looks awesome! Will try to implement this in Defaults
.
In the next major version, we should strictly validate the key name to ensure users don't accidentally make the key's unable to be observed.
The rules are as follows: