Make ParsedAttachment require a URL.
This commit is contained in:
parent
9ad83e58b3
commit
2943fca8e3
@ -172,7 +172,9 @@ private extension RSSInJSONParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let type = enclosureObject["type"] as? String
|
let type = enclosureObject["type"] as? String
|
||||||
let oneAttachment = ParsedAttachment(url: attachmentURL, mimeType: type, title: nil, sizeInBytes: attachmentSize, durationInSeconds: nil)
|
if let attachment = ParsedAttachment(url: attachmentURL, mimeType: type, title: nil, sizeInBytes: attachmentSize, durationInSeconds: nil) {
|
||||||
return Set([oneAttachment])
|
return Set([attachment])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,33 +10,21 @@ import Foundation
|
|||||||
|
|
||||||
public struct ParsedAttachment: Hashable {
|
public struct ParsedAttachment: Hashable {
|
||||||
|
|
||||||
public let url: String?
|
public let url: String
|
||||||
public let mimeType: String?
|
public let mimeType: String?
|
||||||
public let title: String?
|
public let title: String?
|
||||||
public let sizeInBytes: Int?
|
public let sizeInBytes: Int?
|
||||||
public let durationInSeconds: Int?
|
public let durationInSeconds: Int?
|
||||||
public let hashValue: Int
|
public let hashValue: Int
|
||||||
|
|
||||||
init(url: String?, mimeType: String?, title: String?, sizeInBytes: Int?, durationInSeconds: Int?) {
|
init?(url: String, mimeType: String?, title: String?, sizeInBytes: Int?, durationInSeconds: Int?) {
|
||||||
|
|
||||||
self.url = url
|
self.url = url
|
||||||
self.mimeType = mimeType
|
self.mimeType = mimeType
|
||||||
self.title = title
|
self.title = title
|
||||||
self.sizeInBytes = sizeInBytes
|
self.sizeInBytes = sizeInBytes
|
||||||
self.durationInSeconds = durationInSeconds
|
self.durationInSeconds = durationInSeconds
|
||||||
|
self.hashValue = url.hashValue
|
||||||
var stringToHash = ""
|
|
||||||
stringToHash += url ?? ""
|
|
||||||
stringToHash += mimeType ?? ""
|
|
||||||
stringToHash += title ?? ""
|
|
||||||
var h = stringToHash.hashValue
|
|
||||||
if let sizeInBytes = sizeInBytes {
|
|
||||||
h = h ^ sizeInBytes.hashValue
|
|
||||||
}
|
|
||||||
if let durationInSeconds = durationInSeconds {
|
|
||||||
h = h ^ durationInSeconds.hashValue
|
|
||||||
}
|
|
||||||
self.hashValue = h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ==(lhs: ParsedAttachment, rhs: ParsedAttachment) -> Bool {
|
public static func ==(lhs: ParsedAttachment, rhs: ParsedAttachment) -> Bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user