From 622fd51d50cc1fb61b72c85dfa1c0f03f2e0a5b3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 18 Sep 2017 12:59:42 -0700 Subject: [PATCH] Make ArticleStatus a reference type. Make article.status non-optional. --- Frameworks/Data/Article.swift | 6 ++++-- Frameworks/Data/ArticleStatus.swift | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Frameworks/Data/Article.swift b/Frameworks/Data/Article.swift index 45ab00113..25af7f8bf 100644 --- a/Frameworks/Data/Article.swift +++ b/Frameworks/Data/Article.swift @@ -28,9 +28,10 @@ public struct Article: Hashable { public let tags: Set? public let attachments: Set? public let accountInfo: AccountInfo? + public let status: ArticleStatus public let hashValue: Int - public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, tags: Set?, attachments: Set?, accountInfo: AccountInfo?) { + public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, tags: Set?, attachments: Set?, accountInfo: AccountInfo?, status: ArticleStatus) { self.accountID = accountID self.feedID = feedID @@ -49,7 +50,8 @@ public struct Article: Hashable { self.tags = tags self.attachments = attachments self.accountInfo = accountInfo - + self.status = status + if let articleID = articleID { self.articleID = articleID } diff --git a/Frameworks/Data/ArticleStatus.swift b/Frameworks/Data/ArticleStatus.swift index 97d282b0b..988514262 100644 --- a/Frameworks/Data/ArticleStatus.swift +++ b/Frameworks/Data/ArticleStatus.swift @@ -8,6 +8,12 @@ import Foundation +// Threading rules: +// * Main-thread only +// * Except: may be created on background thread by StatusesTable. +// Which is safe, because at creation time it’t not yet shared, +// and it won’t be mutated ever on a background thread. + public enum ArticleStatusKey: String { case read = "read" @@ -15,7 +21,7 @@ public enum ArticleStatusKey: String { case userDeleted = "userDeleted" } -public struct ArticleStatus: Hashable { +public final class ArticleStatus: Hashable { public let articleID: String public let dateArrived: Date @@ -60,7 +66,7 @@ public struct ArticleStatus: Hashable { return false } - public mutating func setBoolStatus(_ status: Bool, forKey key: String) { + public func setBoolStatus(_ status: Bool, forKey key: String) { if let articleStatusKey = ArticleStatusKey(rawValue: key) { switch articleStatusKey {