NetNewsWire/Shared/ExtensionPoints/ExtensionPointIdentifer.swift

78 lines
1.7 KiB
Swift
Raw Normal View History

//
// ExtensionPointIdentifer.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/8/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import Foundation
import FeedProvider
import RSCore
enum ExtensionPointIdentifer: Hashable {
case marsEdit
case microblog
2020-04-15 06:03:08 +02:00
case twitter(String, String)
2020-04-15 06:03:08 +02:00
var extensionPointType: ExtensionPoint.Type {
switch self {
case .marsEdit:
return SendToMarsEditCommand.self
case .microblog:
return SendToMicroBlogCommand.self
case .twitter:
return TwitterFeedProvider.self
}
}
public var userInfo: [AnyHashable: AnyHashable] {
switch self {
case .marsEdit:
return [
"type": "marsEdit"
]
case .microblog:
return [
"type": "microblog"
]
2020-04-15 06:03:08 +02:00
case .twitter(let userID, let screenName):
return [
2020-04-15 06:03:08 +02:00
"type": "twitter",
"userID": userID,
"screenName": screenName
]
}
}
public init?(userInfo: [AnyHashable: AnyHashable]) {
guard let type = userInfo["type"] as? String else { return nil }
switch type {
case "marsEdit":
self = ExtensionPointIdentifer.marsEdit
case "microblog":
self = ExtensionPointIdentifer.microblog
case "twitter":
2020-04-15 06:03:08 +02:00
guard let userID = userInfo["userID"] as? String, let screenName = userInfo["screenName"] as? String else { return nil }
self = ExtensionPointIdentifer.twitter(userID, screenName)
default:
return nil
}
}
public func hash(into hasher: inout Hasher) {
switch self {
case .marsEdit:
hasher.combine("marsEdit")
case .microblog:
hasher.combine("microblog")
2020-04-15 06:03:08 +02:00
case .twitter(let userID, let screenName):
hasher.combine("twitter")
2020-04-15 06:03:08 +02:00
hasher.combine(userID)
hasher.combine(screenName)
}
}
2020-04-15 06:03:08 +02:00
}