Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/AppleStorage/DictionaryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public protocol DictionaryStorage<Key, Value>: Storage {
func delete(key: Key) -> Promise<Void, Error>
func clear() -> Promise<Void, Error>
func get(key: Key) -> Promise<Value?, Error>
func get(limit: Limit) -> Promise<[Value], Error>
func save() -> Promise<Void, Error>
}
16 changes: 16 additions & 0 deletions Source/AppleStorage/Implement/FileDictionaryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ extension FileDictionaryStorage {
}
}
}

public func get(limit: Limit) -> Promise<[Value], Error> {
execute { context in
context.values.capture { values in
let array = Array(values.values)
switch limit {
case .unlimited:
return array
case .count(let limit):
return Array(array.prefix(limit))
}
}
}
}


public func save() -> Promise<Void, Error> {
execute { context in
Expand Down Expand Up @@ -167,3 +182,4 @@ struct FileDictionaryStorageContext<Key: Hashable & Codable, Value: Codable> {

// Must not be modified. Write new ItemVersion and write migration logic instead.
typealias FileDictionaryStorageItemVersion1<Key: Hashable & Codable, Value: Codable> = [Key: Value]