Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced @AtomicArray property wrapper #4

Merged
merged 3 commits into from
Oct 2, 2019
Merged

Conversation

sgr-ksmt
Copy link
Owner

@sgr-ksmt sgr-ksmt commented Oct 1, 2019

I just implemented @AtomicArray property wrapper.

  • Usage
struct Task: Codable {
    var title: String = ""
    @AtomicArray var userIDs: [String] = ["uuuu", "zzzz"]
}

Snapshot<Task>.get(taskPath) { result in
    guard let task = try? result.get() else {
        return 
    }
    
    // replace array
    task.data.userIDs = ["aaa", "bbb"] // => result: ["aaa", "bbb"]
    
    // append element(s) to array
    task.data.$userIDs.union(["xxxx", "yyyy"]) // => result: ["uuuu", "zzzz", "xxxx", "yyyy"]

    // remove element(s) from array
    task.data.$userIDs.remove("zzzz") // => result: ["uuuu"]

    task.update()
}

@sgr-ksmt sgr-ksmt merged commit 8283fea into master Oct 2, 2019
@sgr-ksmt sgr-ksmt deleted the atomic_array branch October 2, 2019 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant