Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dictionarray

Dictionarray is a data type which has both characteristics of Array and Dictionary.

var users: Dictionarray<User> = [
    User(id: "aaa", name: "Chris"),
    User(id: "bbb", name: "Rob"),
    User(id: "ccc", name: "Graydon"),
]

// All following operations run in O(1).
print(users[0].name)         // Chris
print(users[id: "aaa"].name) // Chris

users.append(User(id: "ddd", name: "Martin"))

Elements of Dictionarrays must be conform to Identifiable. ids of elements can be used as keys to get elements from Dictionarrays through subscript(id:).

With SwiftUI

Dictionarray is useful when used combined with SwiftUI's Binding and ForEach.

struct UsersView: View {
    @Binding var users: Dictionarray<User>

    var body: some View {
        LazyVStack {
            ForEach(users.ids, id: \.self) { id in
                UserView($users[id: id])
            }
        }
    }
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages