Fix build errors in Account.framework.

This commit is contained in:
Brent Simmons 2017-09-28 13:16:47 -07:00
parent 1ec3484a95
commit 3a4e545e22
6 changed files with 47 additions and 38 deletions

View File

@ -33,11 +33,16 @@ public final class Account: DisplayNameProvider, Hashable {
let settingsFile: String let settingsFile: String
let dataFolder: String let dataFolder: String
let database: Database let database: Database
var topLevelObjects = [Any]() var topLevelObjects = [AnyObject]()
var feedIDDictionary = [String: Feed]() var feedIDDictionary = [String: Feed]()
var username: String? var username: String?
var refreshInProgress = false var refreshInProgress = false
var supportsSubFolders;
var supportsSubFolders: Bool {
get {
return delegate.supportsSubFolders
}
}
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) { init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
@ -129,45 +134,34 @@ public final class Account: DisplayNameProvider, Hashable {
extension Account { extension Account {
public func plist() -> AnyObject? {
return nil // TODO
}
private struct Key { private struct Key {
static let children = "children" static let children = "children"
} }
func pullObjectsFromDisk() { 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 return
} }
guard let childrenArray = d[Key.children] as? [Any] else { guard let childrenArray = d[Key.children] as? [[String: Any]] else {
return return
} }
topLevelObjects = objects(with: childrenArray) topLevelObjects = objects(with: childrenArray)
updateFeedIDDictionary() updateFeedIDDictionary()
} }
func objects(with diskObjects: [[String: Any]]) -> [Any] { func objects(with diskObjects: [[String: Any]]) -> [AnyObject] {
return diskObjects.flatMap { object(with: $0) } 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 { if Feed.isFeedDictionary(diskObject) {
return nil
}
if diskObjectIsFeed(diskObject) {
return Feed(accountID: accountID, dictionary: diskObject) return Feed(accountID: accountID, dictionary: diskObject)
} }
return Folder(accountID: accountID, dictionary: diskObject) return Folder(account: self, dictionary: diskObject)
}
private func diskObjectIsFeed(_ diskObject: [String: Any]) -> Bool {
return d[Feed.Key.url] != nil
} }
} }

View File

@ -10,6 +10,9 @@ import Foundation
public protocol AccountDelegate { public protocol AccountDelegate {
// Local account does not; some synced accounts might.
var supportsSubFolders: Bool { get }
func refreshAll(for account: Account) func refreshAll(for account: Account)
} }

View File

@ -14,7 +14,7 @@ extension Folder: Container {
public func flattenedFeeds() -> Set<Feed> { public func flattenedFeeds() -> Set<Feed> {
var feeds = Set<Feed>() var feeds = Set<Feed>()
for oneChild in childObjects { for oneChild in children {
if let oneFeed = oneChild as? Feed { if let oneFeed = oneChild as? Feed {
feeds.insert(oneFeed) feeds.insert(oneFeed)
} }
@ -27,14 +27,12 @@ extension Folder: Container {
public func isChild(_ obj: AnyObject) -> Bool { public func isChild(_ obj: AnyObject) -> Bool {
return childObjects.contains(where: { (oneObject) -> Bool in return children.contains { $0 === obj }
return oneObject === obj
})
} }
public func visitObjects(_ recurse: Bool, _ visitBlock: VisitBlock) -> Bool { public func visitObjects(_ recurse: Bool, _ visitBlock: VisitBlock) -> Bool {
for oneObject in childObjects { for oneObject in children {
if let oneContainer = oneObject as? Container { if let oneContainer = oneObject as? Container {
if visitBlock(oneObject) { if visitBlock(oneObject) {

View File

@ -12,14 +12,15 @@ import Data
public final class Folder: DisplayNameProvider, UnreadCountProvider { public final class Folder: DisplayNameProvider, UnreadCountProvider {
public let account: Account public let account: Account
var children = [Any]() var children = [AnyObject]()
var name: String? var name: String?
static let untitledName = NSLocalizedString("Untitled ƒ", comment: "Folder name")
// MARK: - DisplayNameProvider // MARK: - DisplayNameProvider
public var nameForDisplay: String { public var nameForDisplay: String {
get { get {
return name ?? NSLocalizedString("Untitled ƒ", comment: "Folder name") return name ?? Folder.untitledName
} }
} }
@ -47,14 +48,15 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider {
struct Key { struct Key {
static let name = "name" static let name = "name"
static let unreadCount = "unreadCount" static let unreadCount = "unreadCount"
static let childrenKey = "children" static let children = "children"
} }
convenience public init?(account: Account, dictionary: [String: Any]) { convenience public init?(account: Account, dictionary: [String: Any]) {
self.name = dictionary[Key.name] as? String let name = dictionary[Key.name] as? String ?? Folder.untitledName
self.init(account: account, name: name)
if let childrenArray = dictionary[Key.childrenKey] as? [String: Any] { if let childrenArray = dictionary[Key.children] as? [[String: Any]] {
self.children = account.objects(with: childrenArray) self.children = account.objects(with: childrenArray)
} }
@ -74,20 +76,25 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider {
d[Key.unreadCount] = unreadCount d[Key.unreadCount] = unreadCount
} }
// TODO: children as dictionaries - use method in Account
let childObjects = children.flatMap { (child) -> [String: Any]? in let childObjects = children.flatMap { (child) -> [String: Any]? in
if let feed = child as? Feed { 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 return d
} }
} }
} }
extension Folder: OPMLRepresentable { extension Folder: OPMLRepresentable {

View File

@ -10,6 +10,8 @@ import Foundation
struct LocalAccountDelegate: AccountDelegate { struct LocalAccountDelegate: AccountDelegate {
let supportsSubFolders = false
func refreshAll(for account: Account) { func refreshAll(for account: Account) {
// TODO // TODO

View File

@ -52,7 +52,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
// MARK: - Disk Dictionary // MARK: - Disk Dictionary
struct Key { private struct Key {
static let url = "url" static let url = "url"
static let feedID = "feedID" static let feedID = "feedID"
static let homePageURL = "homePageURL" 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] { public var dictionary: [String: Any] {
get { get {
var d = [String: Any]() var d = [String: Any]()
@ -106,7 +111,7 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable {
d[Key.unreadCount] = unreadCount d[Key.unreadCount] = unreadCount
} }
if let conditionalGetInfo = conditionalGetInfo { if let conditionalGetInfo = conditionalGetInfo {
d[Key.conditionalGetInfo] = conditionalGetInfo.dOictionary d[Key.conditionalGetInfo] = conditionalGetInfo.dictionary
} }
return d return d