mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 02:42:54 +00:00
Add ArticleSpecifier — useful to save to disk.
This commit is contained in:
1 parent
ae575b73f1
commit
32fd73e012
1 file changed
+43
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// ArticleSpecifier.swift
|
||||
// Articles
|
||||
//
|
||||
// Created by Brent Simmons on 12/1/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Use this to refer to an Article when you can look it up.
|
||||
///
|
||||
/// For instance, this can be saved to disk as part of state restoration.
|
||||
struct ArticleSpecifier: Hashable, Sendable {
|
||||
let accountID: String
|
||||
let articleID: String
|
||||
|
||||
private struct Key {
|
||||
static let accountID = "accountID"
|
||||
static let articleID = "articleID"
|
||||
}
|
||||
|
||||
/// Plist-compatible dictionary, able to saved to disk or in UserDefaults.
|
||||
var dictionary: [String: String] {
|
||||
[Key.accountID: accountID, Key.articleID: articleID]
|
||||
}
|
||||
|
||||
init(accountID: String, articleID: String) {
|
||||
self.accountID = accountID
|
||||
self.articleID = articleID
|
||||
}
|
||||
|
||||
init?(dictionary: [String: String]) {
|
||||
guard let accountID = dictionary[Key.accountID],
|
||||
let articleID = dictionary[Key.articleID] else {
|
||||
return nil
|
||||
}
|
||||
self.init(accountID: accountID, articleID: articleID)
|
||||
}
|
||||
|
||||
init(article: Article) {
|
||||
self.init(accountID: article.accountID, articleID: article.articleID)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user