From 9a45ab799667ff8469ec4fa484c3c6a793e0da9c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 10 Sep 2017 10:53:24 -0700 Subject: [PATCH] Marked ParsedFeed.hubs a Set. --- .../RSParser/Feeds/JSON/JSONFeedParser.swift | 10 +++++----- Frameworks/RSParser/Feeds/ParsedFeed.swift | 4 ++-- Frameworks/RSParser/Feeds/ParsedHub.swift | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Frameworks/RSParser/Feeds/JSON/JSONFeedParser.swift b/Frameworks/RSParser/Feeds/JSON/JSONFeedParser.swift index 1b4a958aa..b94e2e08a 100644 --- a/Frameworks/RSParser/Feeds/JSON/JSONFeedParser.swift +++ b/Frameworks/RSParser/Feeds/JSON/JSONFeedParser.swift @@ -66,19 +66,19 @@ private extension JSONFeedParser { return [parsedAuthor] } - static func parseHubs(_ dictionary: JSONDictionary) -> [ParsedHub]? { + static func parseHubs(_ dictionary: JSONDictionary) -> Set? { guard let hubsArray = dictionary["hubs"] as? JSONArray else { return nil } - let hubs = hubsArray.flatMap { (oneHubDictionary) -> ParsedHub? in - guard let oneHubURL = oneHubDictionary["url"] as? String, let oneHubType = oneHubDictionary["type"] as? String else { + let hubs = hubsArray.flatMap { (hubDictionary) -> ParsedHub? in + guard let hubURL = hubDictionary["url"] as? String, let hubType = hubDictionary["type"] as? String else { return nil } - return ParsedHub(type: oneHubType, url: oneHubURL) + return ParsedHub(type: hubType, url: hubURL) } - return hubs.isEmpty ? nil : hubs + return hubs.isEmpty ? nil : Set(hubs) } static func parseItems(_ itemsArray: JSONArray, _ feedURL: String) -> Set { diff --git a/Frameworks/RSParser/Feeds/ParsedFeed.swift b/Frameworks/RSParser/Feeds/ParsedFeed.swift index 2cad63fc6..1710fce64 100644 --- a/Frameworks/RSParser/Feeds/ParsedFeed.swift +++ b/Frameworks/RSParser/Feeds/ParsedFeed.swift @@ -20,10 +20,10 @@ public struct ParsedFeed { public let faviconURL: String? public let authors: [ParsedAuthor]? public let expired: Bool - public let hubs: [ParsedHub]? + public let hubs: Set? public let items: Set - init(type: FeedType, title: String?, homePageURL: String?, feedURL: String?, feedDescription: String?, nextURL: String?, iconURL: String?, faviconURL: String?, authors: [ParsedAuthor]?, expired: Bool, hubs: [ParsedHub]?, items: Set) { + init(type: FeedType, title: String?, homePageURL: String?, feedURL: String?, feedDescription: String?, nextURL: String?, iconURL: String?, faviconURL: String?, authors: [ParsedAuthor]?, expired: Bool, hubs: Set?, items: Set) { self.type = type self.title = title diff --git a/Frameworks/RSParser/Feeds/ParsedHub.swift b/Frameworks/RSParser/Feeds/ParsedHub.swift index 961799570..e328c5cdd 100644 --- a/Frameworks/RSParser/Feeds/ParsedHub.swift +++ b/Frameworks/RSParser/Feeds/ParsedHub.swift @@ -8,8 +8,21 @@ import Foundation -public struct ParsedHub { +public struct ParsedHub: Hashable { - public let type: String? - public let url: String? + public let type: String + public let url: String + public let hashValue: Int + + init(type: String, url: String) { + + self.type = type + self.url = url + self.hashValue = type.hashValue ^ url.hashValue + } + + public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool { + + return lhs.type == rhs.type && lhs.url == rhs.url + } }