NetNewsWire/Frameworks/Database/AuthorsManager.swift

41 lines
741 B
Swift

//
// 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
}
}