Sync
is a Swift package that provides a Macro to synchronize properties across different instances. Sync
ensures that your properties stay in sync, reflecting changes instantaneously and reliably, without resorting to manually writing boilerplate.
Syncing is performed when the property the macro is applied to is set or read. With that in mind, it's most useful on properties that contain value types (structs and enums).
Our primary use case for this package is with The Composable Architecture, where we use it to share state across different components of the application.
import Sync
struct UserProfile {
var name: String
var email: String
@Sync(
(\SessionInfo.username, to: \UserProfile.name),
(\SessionInfo.email, to: \UserProfile.email)
)
var sessionInfo: SessionInfo
init() {
name = "John Doe"
email = "[email protected]"
_sessionInfo = SessionInfo(username: name, email: email)
}
}
struct SessionInfo {
var username: String
var isLoggedIn: Bool = false
}
This library is released under the MIT license. See LICENSE for details.