Adds history browser view
This commit is contained in:
@@ -37,10 +37,19 @@ class BrowserHistory
|
||||
}
|
||||
}
|
||||
|
||||
public func allHistory() -> [HistoryItem] {
|
||||
public func allHistory(limit: Int? = nil) -> [HistoryItem] {
|
||||
let dataContext = persistentContainer.viewContext
|
||||
|
||||
let fetchRequest: NSFetchRequest<HistoryItemEntity> = HistoryItemEntity.fetchRequest()
|
||||
fetchRequest.sortDescriptors = [
|
||||
// Sort by date
|
||||
NSSortDescriptor(keyPath: \HistoryItemEntity.lastVisited, ascending: false)
|
||||
]
|
||||
|
||||
if let limit {
|
||||
fetchRequest.fetchLimit = limit
|
||||
}
|
||||
|
||||
let entities: [HistoryItemEntity] = (try? dataContext.fetch(fetchRequest)) ?? []
|
||||
|
||||
return entities.map { (entity) -> HistoryItem in
|
||||
|
||||
Reference in New Issue
Block a user