Make a mess of things. Article and ArticleStatus are now immutable structs.

This commit is contained in:
Brent Simmons
2017-09-04 17:10:02 -07:00
parent fb121f8a8c
commit b0cb01a68e
13 changed files with 560 additions and 119 deletions

View File

@@ -15,14 +15,14 @@ public enum ArticleStatusKey: String {
case userDeleted = "userDeleted"
}
public final class ArticleStatus: Hashable {
public struct ArticleStatus: Hashable {
public var read = false
public var starred = false
public var userDeleted = false
public var dateArrived: Date
public let articleID: String
public var accountInfo: AccountInfo?
public let read = false
public let starred = false
public let userDeleted = false
public let dateArrived: Date
public let accountInfo: AccountInfo?
public let hashValue: Int
public init(articleID: String, read: Bool, starred: Bool, userDeleted: Bool, dateArrived: Date, accountInfo: AccountInfo?) {
@@ -59,28 +59,28 @@ public final class ArticleStatus: Hashable {
return false
}
public func setBoolStatus(_ status: Bool, forKey key: String) {
if let articleStatusKey = ArticleStatusKey(rawValue: key) {
switch articleStatusKey {
case .read:
read = status
case .starred:
starred = status
case .userDeleted:
userDeleted = status
}
}
else {
if accountInfo == nil {
accountInfo = AccountInfo()
}
accountInfo![key] = status
}
}
// public func setBoolStatus(_ status: Bool, forKey key: String) {
//
// if let articleStatusKey = ArticleStatusKey(rawValue: key) {
// switch articleStatusKey {
// case .read:
// read = status
// case .starred:
// starred = status
// case .userDeleted:
// userDeleted = status
// }
// }
// else {
// if accountInfo == nil {
// accountInfo = AccountInfo()
// }
// accountInfo![key] = status
// }
// }
public class func ==(lhs: ArticleStatus, rhs: ArticleStatus) -> Bool {
return lhs.articleID == rhs.articleID && lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred
return lhs.hashValue == rhs.hashValue && lhs.articleID == rhs.articleID && lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred && lhs.userDeleted == rhs.userDeleted && lhs.accountInfo == rhs.accountInfo
}
}