mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 06:30:31 +01:00
Fix build errors in Account.framework.
This commit is contained in:
parent
1ec3484a95
commit
3a4e545e22
@ -33,11 +33,16 @@ public final class Account: DisplayNameProvider, Hashable {
|
||||
let settingsFile: String
|
||||
let dataFolder: String
|
||||
let database: Database
|
||||
var topLevelObjects = [Any]()
|
||||
var topLevelObjects = [AnyObject]()
|
||||
var feedIDDictionary = [String: Feed]()
|
||||
var username: String?
|
||||
var refreshInProgress = false
|
||||
var supportsSubFolders;
|
||||
|
||||
var supportsSubFolders: Bool {
|
||||
get {
|
||||
return delegate.supportsSubFolders
|
||||
}
|
||||
}
|
||||
|
||||
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
|
||||
|
||||
@ -129,45 +134,34 @@ public final class Account: DisplayNameProvider, Hashable {
|
||||
|
||||
extension Account {
|
||||
|
||||
public func plist() -> AnyObject? {
|
||||
return nil // TODO
|
||||
}
|
||||
|
||||
private struct Key {
|
||||
static let children = "children"
|
||||
}
|
||||
|
||||
func pullObjectsFromDisk() {
|
||||
|
||||
guard let d = NSDictionary(contentsOf: settingsFile) as? [String: Any] else {
|
||||
let settingsFileURL = URL(fileURLWithPath: settingsFile)
|
||||
guard let d = NSDictionary(contentsOf: settingsFileURL) as? [String: Any] else {
|
||||
return
|
||||
}
|
||||
guard let childrenArray = d[Key.children] as? [Any] else {
|
||||
guard let childrenArray = d[Key.children] as? [[String: Any]] else {
|
||||
return
|
||||
}
|
||||
topLevelObjects = objects(with: childrenArray)
|
||||
updateFeedIDDictionary()
|
||||
}
|
||||
|
||||
func objects(with diskObjects: [[String: Any]]) -> [Any] {
|
||||
func objects(with diskObjects: [[String: Any]]) -> [AnyObject] {
|
||||
|
||||
return diskObjects.flatMap { object(with: $0) }
|
||||
}
|
||||
|
||||
func object(with diskObject: Any) -> Any {
|
||||
func object(with diskObject: [String: Any]) -> AnyObject? {
|
||||
|
||||
guard let d = diskObject as? [String: Any] else {
|
||||
return nil
|
||||
}
|
||||
if diskObjectIsFeed(diskObject) {
|
||||
if Feed.isFeedDictionary(diskObject) {
|
||||
return Feed(accountID: accountID, dictionary: diskObject)
|
||||
}
|
||||
return Folder(accountID: accountID, dictionary: diskObject)
|
||||
}
|
||||
|
||||
private func diskObjectIsFeed(_ diskObject: [String: Any]) -> Bool {
|
||||
|
||||
return d[Feed.Key.url] != nil
|
||||
return Folder(account: self, dictionary: diskObject)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,9 @@ import Foundation
|
||||
|
||||
public protocol AccountDelegate {
|
||||
|
||||
// Local account does not; some synced accounts might.
|
||||
var supportsSubFolders: Bool { get }
|
||||
|
||||
func refreshAll(for account: Account)
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ extension Folder: Container {
|
||||
public func flattenedFeeds() -> Set<Feed> {
|
||||
|
||||
var feeds = Set<Feed>()
|
||||
for oneChild in childObjects {
|
||||
for oneChild in children {
|
||||
if let oneFeed = oneChild as? Feed {
|
||||
feeds.insert(oneFeed)
|
||||
}
|
||||
@ -27,14 +27,12 @@ extension Folder: Container {
|
||||
|
||||
public func isChild(_ obj: AnyObject) -> Bool {
|
||||
|
||||
return childObjects.contains(where: { (oneObject) -> Bool in
|
||||
return oneObject === obj
|
||||
})
|
||||
return children.contains { $0 === obj }
|
||||
}
|
||||
|
||||
public func visitObjects(_ recurse: Bool, _ visitBlock: VisitBlock) -> Bool {
|
||||
|
||||
for oneObject in childObjects {
|
||||
for oneObject in children {
|
||||
|
||||
if let oneContainer = oneObject as? Container {
|
||||
if visitBlock(oneObject) {
|
||||
|
@ -12,14 +12,15 @@ import Data
|
||||
public final class Folder: DisplayNameProvider, UnreadCountProvider {
|
||||
|
||||
public let account: Account
|
||||
var children = [Any]()
|
||||
var children = [AnyObject]()
|
||||
var name: String?
|
||||
static let untitledName = NSLocalizedString("Untitled ƒ", comment: "Folder name")
|
||||
|
||||
// MARK: - DisplayNameProvider
|
||||
|
||||
public var nameForDisplay: String {
|
||||
get {
|
||||
return name ?? NSLocalizedString("Untitled ƒ", comment: "Folder name")
|
||||
return name ?? Folder.untitledName
|
||||
|
||||
}
|
||||
}
|
||||
@ -47,14 +48,15 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider {
|
||||
struct Key {
|
||||
static let name = "name"
|
||||
static let unreadCount = "unreadCount"
|
||||
static let childrenKey = "children"
|
||||
static let children = "children"
|
||||
}
|
||||
|
||||
convenience public init?(account: Account, dictionary: [String: Any]) {
|
||||
|
||||
self.name = dictionary[Key.name] as? String
|
||||
|
||||
if let childrenArray = dictionary[Key.childrenKey] as? [String: Any] {
|
||||
let name = dictionary[Key.name] as? String ?? Folder.untitledName
|
||||
self.init(account: account, name: name)
|
||||
|
||||
if let childrenArray = dictionary[Key.children] as? [[String: Any]] {
|
||||
self.children = account.objects(with: childrenArray)
|
||||
}
|
||||
|
||||
@ -74,20 +76,25 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider {
|
||||
d[Key.unreadCount] = unreadCount
|
||||
}
|
||||
|
||||
// TODO: children as dictionaries - use method in Account
|
||||
|
||||
|
||||
let childObjects = children.flatMap { (child) -> [String: Any]? in
|
||||
|
||||
if let feed = child as? Feed {
|
||||
|
||||
return feed.dictionary
|
||||
}
|
||||
if let folder = child as? Folder, account.supportsSubFolders {
|
||||
return folder.dictionary
|
||||
}
|
||||
assertionFailure("Expected a feed or a folder.");
|
||||
return nil
|
||||
}
|
||||
|
||||
if !childObjects.isEmpty {
|
||||
d[Key.children] = childObjects
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Folder: OPMLRepresentable {
|
||||
|
@ -10,6 +10,8 @@ import Foundation
|
||||
|
||||
struct LocalAccountDelegate: AccountDelegate {
|
||||
|
||||
let supportsSubFolders = false
|
||||
|
||||
func refreshAll(for account: Account) {
|
||||
|
||||
// TODO
|
||||
|
@ -52,7 +52,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||
|
||||
// MARK: - Disk Dictionary
|
||||
|
||||
struct Key {
|
||||
private struct Key {
|
||||
static let url = "url"
|
||||
static let feedID = "feedID"
|
||||
static let homePageURL = "homePageURL"
|
||||
@ -84,6 +84,11 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
public static func isFeedDictionary(_ d: [String: Any]) -> Bool {
|
||||
|
||||
return d[Key.url] != nil
|
||||
}
|
||||
|
||||
public var dictionary: [String: Any] {
|
||||
get {
|
||||
var d = [String: Any]()
|
||||
@ -106,7 +111,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
|
||||
d[Key.unreadCount] = unreadCount
|
||||
}
|
||||
if let conditionalGetInfo = conditionalGetInfo {
|
||||
d[Key.conditionalGetInfo] = conditionalGetInfo.dOictionary
|
||||
d[Key.conditionalGetInfo] = conditionalGetInfo.dictionary
|
||||
}
|
||||
|
||||
return d
|
||||
|
Loading…
Reference in New Issue
Block a user