2019-11-25 01:29:00 +01:00
|
|
|
//
|
|
|
|
// ContainerIdentifier.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/24/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public protocol ContainerIdentifiable {
|
|
|
|
var containerID: ContainerIdentifier? { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum ContainerIdentifier: Hashable {
|
|
|
|
case smartFeedController
|
|
|
|
case account(String) // accountID
|
|
|
|
case folder(String, String) // accountID, folderName
|
2019-11-26 23:33:11 +01:00
|
|
|
|
2019-11-27 18:43:36 +01:00
|
|
|
public var userInfo: [AnyHashable: AnyHashable] {
|
2019-11-26 23:33:11 +01:00
|
|
|
switch self {
|
|
|
|
case .smartFeedController:
|
|
|
|
return [
|
|
|
|
"type": "smartFeedController"
|
|
|
|
]
|
|
|
|
case .account(let accountID):
|
|
|
|
return [
|
|
|
|
"type": "account",
|
|
|
|
"accountID": accountID
|
|
|
|
]
|
|
|
|
case .folder(let accountID, let folderName):
|
|
|
|
return [
|
|
|
|
"type": "folder",
|
|
|
|
"accountID": accountID,
|
|
|
|
"folderName": folderName
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:43:36 +01:00
|
|
|
public init?(userInfo: [AnyHashable: AnyHashable]) {
|
2019-11-26 23:33:11 +01:00
|
|
|
guard let type = userInfo["type"] as? String else { return nil }
|
|
|
|
|
|
|
|
switch type {
|
|
|
|
case "smartFeedController":
|
|
|
|
self = ContainerIdentifier.smartFeedController
|
|
|
|
case "account":
|
|
|
|
guard let accountID = userInfo["accountID"] as? String else { return nil }
|
|
|
|
self = ContainerIdentifier.account(accountID)
|
|
|
|
case "folder":
|
|
|
|
guard let accountID = userInfo["accountID"] as? String, let folderName = userInfo["folderName"] as? String else { return nil }
|
|
|
|
self = ContainerIdentifier.folder(accountID, folderName)
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 01:29:00 +01:00
|
|
|
}
|