Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1.22 KB

README.md

File metadata and controls

39 lines (28 loc) · 1.22 KB

Sync

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.

Usage

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
}

License

This library is released under the MIT license. See LICENSE for details.