2017-09-16 15:25:38 -07:00
|
|
|
//
|
|
|
|
// Folder+Container.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 9/16/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2017-09-17 12:08:50 -07:00
|
|
|
import Data
|
2017-09-16 15:25:38 -07:00
|
|
|
|
|
|
|
extension Folder: Container {
|
|
|
|
|
|
|
|
public func flattenedFeeds() -> Set<Feed> {
|
|
|
|
|
|
|
|
var feeds = Set<Feed>()
|
2017-09-28 13:16:47 -07:00
|
|
|
for oneChild in children {
|
2017-09-16 15:25:38 -07:00
|
|
|
if let oneFeed = oneChild as? Feed {
|
|
|
|
feeds.insert(oneFeed)
|
|
|
|
}
|
|
|
|
else if let oneContainer = oneChild as? Container {
|
|
|
|
feeds.formUnion(oneContainer.flattenedFeeds())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return feeds
|
|
|
|
}
|
|
|
|
|
|
|
|
public func isChild(_ obj: AnyObject) -> Bool {
|
|
|
|
|
2017-09-28 13:16:47 -07:00
|
|
|
return children.contains { $0 === obj }
|
2017-09-16 15:25:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public func visitObjects(_ recurse: Bool, _ visitBlock: VisitBlock) -> Bool {
|
|
|
|
|
2017-09-28 13:16:47 -07:00
|
|
|
for oneObject in children {
|
2017-09-16 15:25:38 -07:00
|
|
|
|
|
|
|
if let oneContainer = oneObject as? Container {
|
|
|
|
if visitBlock(oneObject) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if recurse && oneContainer.visitObjects(recurse, visitBlock) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if visitBlock(oneObject) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|