Created
December 3, 2015 00:27
-
-
Save mgp/b76958e4b965fe56aa60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SearchFilterSequence.swift | |
// Khan Academy | |
// | |
// Created by Mike Parker on 12/2/15. | |
// Copyright © 2015 Khan Academy. All rights reserved. | |
// | |
import Foundation | |
public struct SearchFilterSequence { | |
public let values: [SearchFilter] | |
/// Returns the SearchFilter instances that are selected. | |
public var selectedFilters: [SearchFilter] { | |
return values.filter { $0.selected } | |
} | |
/// Returns whether the filter for offline content is selected. | |
public var isAvailableOfflineSelected: Bool { | |
return values.any { filter in | |
switch filter.predicate { | |
case .AvailableOfflinePredicate: | |
return filter.selected | |
default: | |
return false | |
} | |
} | |
} | |
/// Returns the domain names for the selected topic filters. | |
public var selectedTopicDomainNames: [String] { | |
return selectedFilters.flatMap { filter in | |
switch filter.predicate { | |
case .TopicPredicate: | |
return filter.localizedName | |
default: | |
return nil | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment