mastodon-ios/Mastodon/Diffiable/Item/PollItem.swift

52 lines
1.0 KiB
Swift
Raw Normal View History

//
// PollItem.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-2.
//
import Foundation
import CoreData
enum PollItem {
2021-03-02 12:10:45 +01:00
case opion(objectID: NSManagedObjectID, attribute: Attribute)
}
extension PollItem {
class Attribute: Hashable {
var voted: Bool = false
2021-03-02 12:10:45 +01:00
init(voted: Bool = false) {
self.voted = voted
}
static func == (lhs: PollItem.Attribute, rhs: PollItem.Attribute) -> Bool {
return lhs.voted == rhs.voted
}
func hash(into hasher: inout Hasher) {
hasher.combine(voted)
}
}
}
extension PollItem: Equatable {
static func == (lhs: PollItem, rhs: PollItem) -> Bool {
switch (lhs, rhs) {
2021-03-02 12:10:45 +01:00
case (.opion(let objectIDLeft, _), .opion(let objectIDRight, _)):
return objectIDLeft == objectIDRight
}
}
}
extension PollItem: Hashable {
func hash(into hasher: inout Hasher) {
switch self {
2021-03-02 12:10:45 +01:00
case .opion(let objectID, _):
hasher.combine(objectID)
}
}
}