// // ArticlesManager.swift // Evergreen // // Created by Brent Simmons on 5/9/16. // Copyright © 2016 Ranchero Software, LLC. All rights reserved. // import Foundation import Data final class ArticlesManager { private let cachedArticles: NSMapTable = NSMapTable.weakToWeakObjects() func uniquedArticles(_ fetchedArticles: Set
, statusesManager: StatusesManager) -> Set
{ var articles = Set
() for oneArticle in fetchedArticles { assert(oneArticle.status != nil) if let existingArticle = cachedArticle(oneArticle.articleID) { articles.insert(existingArticle) } else { cacheArticle(oneArticle) articles.insert(oneArticle) } } statusesManager.attachCachedStatuses(articles) return articles } func cachedArticle(_ articleID: String) -> Article? { return cachedArticles.object(forKey: articleID as NSString) } func cacheArticle(_ article: Article) { cachedArticles.setObject(article, forKey: article.articleID as NSString) } func cacheArticles(_ articles: Set
) { articles.forEach { cacheArticle($0) } } }