Make tags and attachments sets instead of arrays.

This commit is contained in:
Brent Simmons
2017-09-10 11:18:15 -07:00
parent b1bd1ac75a
commit 9ad83e58b3
4 changed files with 37 additions and 16 deletions

View File

@@ -141,23 +141,21 @@ private extension RSSInJSONParser {
return Set([parsedAuthor])
}
static func parseTags(_ itemDictionary: JSONDictionary) -> [String]? {
static func parseTags(_ itemDictionary: JSONDictionary) -> Set<String>? {
if let categoryObject = itemDictionary["category"] as? JSONDictionary {
if let oneTag = categoryObject["#value"] as? String {
return [oneTag]
return Set([oneTag])
}
return nil
}
else if let categoryArray = itemDictionary["category"] as? JSONArray {
return categoryArray.flatMap{ (categoryObject) in
return categoryObject["#value"] as? String
}
return Set(categoryArray.flatMap{ $0["#value"] as? String })
}
return nil
}
static func parseAttachments(_ itemDictionary: JSONDictionary) -> [ParsedAttachment]? {
static func parseAttachments(_ itemDictionary: JSONDictionary) -> Set<ParsedAttachment>? {
guard let enclosureObject = itemDictionary["enclosure"] as? JSONDictionary else {
return nil
@@ -175,6 +173,6 @@ private extension RSSInJSONParser {
let type = enclosureObject["type"] as? String
let oneAttachment = ParsedAttachment(url: attachmentURL, mimeType: type, title: nil, sizeInBytes: attachmentSize, durationInSeconds: nil)
return [oneAttachment]
return Set([oneAttachment])
}
}