yattee/Model/Playlist.swift

29 lines
724 B
Swift
Raw Normal View History

2021-06-26 09:39:35 +00:00
import Foundation
import SwiftyJSON
struct Playlist: Identifiable, Equatable, Hashable {
2021-06-26 09:39:35 +00:00
let id: String
var title: String
2021-07-08 17:18:36 +00:00
var visibility: PlaylistVisibility
2021-06-26 09:39:35 +00:00
var updated: TimeInterval
2021-06-26 09:39:35 +00:00
var videos = [Video]()
init(_ json: JSON) {
id = json["playlistId"].stringValue
title = json["title"].stringValue
2021-07-08 17:18:36 +00:00
visibility = json["isListed"].boolValue ? .public : .private
updated = json["updated"].doubleValue
2021-06-26 09:39:35 +00:00
videos = json["videos"].arrayValue.map { Video($0) }
}
static func == (lhs: Playlist, rhs: Playlist) -> Bool {
lhs.id == rhs.id && lhs.updated == rhs.updated
2021-06-26 09:39:35 +00:00
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}