aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models/NewsCategory.swift
blob: 0ba87a7e4469fd623070c6d8ec4bb13b0560fc7e (plain)
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
import SwiftUI

enum NewsCategoryType {
  case bundle
  case category
}

@Observable class NewsCategory: Identifiable, Hashable {
  let id: UUID = UUID()
  
  let name: String
  let count: UInt16
  let type: NewsCategoryType
  
  init(hotlineNewsCategory: HotlineNewsCategory) {
    self.name = hotlineNewsCategory.name
    self.count = hotlineNewsCategory.count
    
    if hotlineNewsCategory.type == 2 {
      self.type = .bundle
    }
    else {
      self.type = .category
    }
  }
  
  func hash(into hasher: inout Hasher) {
    hasher.combine(self.id)
  }
  
  static func == (lhs: NewsCategory, rhs: NewsCategory) -> Bool {
    return lhs.id == rhs.id
  }
}