Last active
April 25, 2020 17:27
-
-
Save lightsprint09/328d43a03bf33853ff6d9bcb42f2c365 to your computer and use it in GitHub Desktop.
Automerge Swift API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MyModel { | |
let created: Date | |
var mutableData: [String] | |
var text: Text | |
} | |
let content = MyModel(created: Date(), mutableData: [], text: Text("hi")) | |
let document = Automerge<MyModel>(content: content) | |
// accessing data | |
document.created // Use dynamic member lookup | |
document.content.created // or just expose the whole content | |
document.change(message: "change", { doc in | |
doc.[\.mutableData, "\.mutableData"].set(["hi", "hello"]) | |
//Static keyPath helpf to get compile support | |
// dynamic keypath is needed, because there is no KeyPath Reflection/Serialization at the moment | |
doc.[\.mutableData, "\.mutableData"].append("good morning") | |
// Append is compiled checked, because the Key Paths knows it is an array | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment