forked from insidegui/WWDC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeaturedSection.swift
94 lines (74 loc) · 2.97 KB
/
FeaturedSection.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// FeaturedSection.swift
// ConfCore
//
// Created by Guilherme Rambo on 26/05/18.
// Copyright © 2018 Guilherme Rambo. All rights reserved.
//
import Foundation
import RealmSwift
public enum FeaturedSectionFormat: String {
// Standard formats from Apple
case largeGrid = "large_grid"
case smallGrid = "small_grid"
// Custom format for curated playlists
case curated = "curated_wwdc.io"
// Special dynamic sections
case history = "_history"
case favorites = "_favorites"
case live = "_live"
case upNext = "_next"
}
/// Specifies a playlist that's shown in the Featured tab
public class FeaturedSection: Object, Decodable {
/// The order in which to display the featured section
@objc public dynamic var order = 0
/// Whether this section is published and should be displayed
@objc public dynamic var isPublished = true
@objc dynamic var rawFormat: String = ""
/// The format for the section layout
public var format: FeaturedSectionFormat? {
get {
return FeaturedSectionFormat(rawValue: rawFormat)
}
set {
rawFormat = newValue?.rawValue ?? ""
}
}
@objc public dynamic var title: String = ""
@objc public dynamic var summary: String = ""
@objc public dynamic var colorA: String?
@objc public dynamic var colorB: String?
@objc public dynamic var colorC: String?
/// Contains a list of contents which are sessions that can have an associated essay and bookmarks
public let content = List<FeaturedContent>()
/// When the section is a curated one, contains information for the author
@objc public dynamic var author: FeaturedAuthor?
public override static func ignoredProperties() -> [String] {
return ["format"]
}
public override static func primaryKey() -> String? {
return "title"
}
// MARK: - Codable
private enum CodingKeys: String, CodingKey {
case ordinal, format, title, description, content, author, published
case colorA = "ios_color"
case colorB = "tvos_light_style_color"
case colorC = "tvos_dark_style_color"
}
public required convenience init(from decoder: Decoder) throws {
self.init()
let container = try decoder.container(keyedBy: CodingKeys.self)
content.append(objectsIn: try container.decode([FeaturedContent].self, forKey: .content))
author = try container.decodeIfPresent(key: .author)
order = try container.decode(key: .ordinal)
isPublished = try container.decodeIfPresent(key: .published) ?? true
rawFormat = try container.decodeIfPresent(key: .format) ?? FeaturedSectionFormat.largeGrid.rawValue
title = try container.decode(key: .title)
summary = try container.decode(key: .description)
colorA = try container.decodeIfPresent(key: .colorA)
colorB = try container.decodeIfPresent(key: .colorB)
colorC = try container.decodeIfPresent(key: .colorC)
}
}