diff --git a/Example/Example/UIKit/MagicBellStoreViewController.swift b/Example/Example/UIKit/MagicBellStoreViewController.swift index bf40129..bd47404 100644 --- a/Example/Example/UIKit/MagicBellStoreViewController.swift +++ b/Example/Example/UIKit/MagicBellStoreViewController.swift @@ -138,7 +138,7 @@ class MagicBellStoreViewController: UITableViewController, self.configureStore(predicate: StorePredicate(archived: true)) }) alert.addAction(UIAlertAction(title: "By Category", style: .default) { _ in - self.configureStore(predicate: StorePredicate(categories: ["order_created"])) + self.configureStore(predicate: StorePredicate(category: "order_created")) }) alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) self.present(alert, animated: true, completion: nil) diff --git a/Source/Features/Store/Data/StoreContext+QueryItems.swift b/Source/Features/Store/Data/StoreContext+QueryItems.swift index 251800d..ba45cd6 100644 --- a/Source/Features/Store/Data/StoreContext+QueryItems.swift +++ b/Source/Features/Store/Data/StoreContext+QueryItems.swift @@ -25,10 +25,10 @@ extension StorePredicate { } } - for category in categories { + if let category = category { queryItems.append(URLQueryItem(name: "category", value: category)) } - for topic in topics { + if let topic = topic { queryItems.append(URLQueryItem(name: "topic", value: topic)) } diff --git a/Source/Features/Store/NotificationValidator.swift b/Source/Features/Store/NotificationValidator.swift index e4f924e..b410ca0 100644 --- a/Source/Features/Store/NotificationValidator.swift +++ b/Source/Features/Store/NotificationValidator.swift @@ -59,20 +59,20 @@ struct NotificationValidator { } func validateCategory(_ notification: Notification) -> Bool { - if predicate.categories.isEmpty { + if predicate.category == nil { return true } else if let category = notification.category { - return predicate.categories.contains(category) + return predicate.category == category } else { return false } } func validateTopic(_ notification: Notification) -> Bool { - if predicate.topics.isEmpty { + if predicate.topic == nil { return true } else if let topic = notification.topic { - return predicate.topics.contains(topic) + return predicate.topic == topic } else { return false } diff --git a/Source/Features/Store/StoreDirector.swift b/Source/Features/Store/StoreDirector.swift index cd9ad20..784890c 100644 --- a/Source/Features/Store/StoreDirector.swift +++ b/Source/Features/Store/StoreDirector.swift @@ -49,14 +49,14 @@ public extension StoreDirector { /// Build a store based on the category of notifications /// - Returns: A notification store - func build(categories: [String]) -> NotificationStore { - return build(predicate: StorePredicate(categories: categories)) + func build(category: String) -> NotificationStore { + return build(predicate: StorePredicate(category: category)) } /// Build a store based on the topic of notifications /// - Returns: A notification store - func build(topics: [String]) -> NotificationStore { - return build(predicate: StorePredicate(topics: topics)) + func build(topic: String) -> NotificationStore { + return build(predicate: StorePredicate(topic: topic)) } } diff --git a/Source/Features/Store/StorePredicate.swift b/Source/Features/Store/StorePredicate.swift index fed382c..aeaaa60 100644 --- a/Source/Features/Store/StorePredicate.swift +++ b/Source/Features/Store/StorePredicate.swift @@ -14,40 +14,44 @@ import Foundation /// The notificaiton store predicate -public struct StorePredicate: Hashable, Equatable { +public struct StorePredicate { public let read: Bool? public let seen: Bool? public let archived: Bool - public let categories: [String] - public let topics: [String] + public let category: String? + public let topic: String? /// Predicate default initializer /// - Parameters: /// - read: The read status. Defaults to `nil` (not specified). /// - seen: The seen status. Defaults to `nil` (not specified). /// - archived: The archived status. Defaults to `false` (unarchived). - /// - categories: The list of categories. Defaults to empty array. - /// - topics: The list of topics. Defaults to empty array. + /// - category: The category. Defaults to nil. + /// - topic: The topic. Defaults to nil. public init(read: Bool? = nil, seen: Bool? = nil, archived: Bool = false, - categories: [String] = [], - topics: [String] = []) { + category: String? = nil, + topic: String? = nil) { self.read = read self.seen = seen self.archived = archived - self.categories = categories - self.topics = topics + self.category = category + self.topic = topic } +} +extension StorePredicate: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(read.hashValue) hasher.combine(seen.hashValue) hasher.combine(archived.hashValue) - hasher.combine(categories.hashValue) - hasher.combine(topics.hashValue) + hasher.combine(category.hashValue) + hasher.combine(topic.hashValue) } +} +extension StorePredicate: Equatable { public static func == (lhs: StorePredicate, rhs: StorePredicate) -> Bool { if lhs.read != rhs.read { return false @@ -58,10 +62,10 @@ public struct StorePredicate: Hashable, Equatable { if lhs.archived != rhs.archived { return false } - if lhs.categories != rhs.categories { + if lhs.category != rhs.category { return false } - if lhs.topics != rhs.topics { + if lhs.topic != rhs.topic { return false } return true