NetNewsWire/Frameworks/Database/AuthorsManager.swift

41 lines
741 B
Swift
Raw Normal View History

2017-07-13 22:38:47 +02:00
//
// AuthorsManager.swift
// Database
//
// Created by Brent Simmons on 7/13/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import Data
final class AuthorsManager {
var cachedAuthors = [String: Author]()
func cachedAuthor(_ databaseID: String) -> Author? {
return cachedAuthors[databaseID]
}
func cacheAuthor(_ author: Author) {
cachedAuthors[author.databaseID] = author
}
func authorWithRow(_ row: FMResultSet) -> Author? {
let databaseID = row.string(forColumn: DatabaseKey.databaseID)
if let author = cachedAuthor(databaseID) {
return author
}
guard let author = Author(row: row) else {
return nil
}
cacheAuthor(author)
return author
}
}