From 0910003de72a0485826c442ad5bf1a0d4995f47c Mon Sep 17 00:00:00 2001 From: Reed Es Date: Sun, 24 Oct 2021 10:46:41 -0600 Subject: [PATCH] added emptyKey property to support pickers (#4) * added emptyKey property to support pickers --- README.md | 3 +++ Sources/Core/AllocKeyed.swift | 1 + Sources/Model/Account/MAccount+Key.swift | 4 ++++ Sources/Model/Allocation/MAllocation+Key.swift | 4 ++++ Sources/Model/Asset/MAsset+Key.swift | 4 ++++ Sources/Model/Cap/MCap+Key.swift | 4 ++++ Sources/Model/Holding/MHolding+Key.swift | 4 ++++ .../Model/Rebalance/Allocation/MRebalanceAllocation+Key.swift | 4 ++++ Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift | 4 ++++ Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift | 4 ++++ Sources/Model/Security/MSecurity+Key.swift | 4 ++++ Sources/Model/Source/Meta/MSourceMeta+Key.swift | 4 ++++ Sources/Model/Strategy/MStrategy+Key.swift | 4 ++++ Sources/Model/Tracker/MTracker+Key.swift | 4 ++++ Sources/Model/Transaction/MTransaction+Key.swift | 4 ++++ Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift | 4 ++++ Sources/Model/Valuation/Position/MValuationPosition+Key.swift | 4 ++++ Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift | 4 ++++ 18 files changed, 68 insertions(+) diff --git a/README.md b/README.md index 3782b4b..79e555b 100644 --- a/README.md +++ b/README.md @@ -262,11 +262,14 @@ Used to retrieve and generate the entity's primary key. This new struct-based implementation replaces the old string-based one. +The `emptyKey` property can be used for picker tag values, as an example. + ```swift public protocol AllocKeyed: Hashable { associatedtype Key: Hashable, Codable var primaryKey: Key { get } + static var emptyKey: Key { get } } ``` diff --git a/Sources/Core/AllocKeyed.swift b/Sources/Core/AllocKeyed.swift index 8d8ac1c..a70675f 100644 --- a/Sources/Core/AllocKeyed.swift +++ b/Sources/Core/AllocKeyed.swift @@ -21,6 +21,7 @@ public protocol AllocKeyed: Hashable { associatedtype Key: Hashable, Codable var primaryKey: Key { get } + static var emptyKey: Key { get } } public extension AllocKeyed { diff --git a/Sources/Model/Account/MAccount+Key.swift b/Sources/Model/Account/MAccount+Key.swift index 8f10d55..a4f2cdc 100644 --- a/Sources/Model/Account/MAccount+Key.swift +++ b/Sources/Model/Account/MAccount+Key.swift @@ -33,4 +33,8 @@ extension MAccount: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "") + } } diff --git a/Sources/Model/Allocation/MAllocation+Key.swift b/Sources/Model/Allocation/MAllocation+Key.swift index 8ce5890..068085f 100644 --- a/Sources/Model/Allocation/MAllocation+Key.swift +++ b/Sources/Model/Allocation/MAllocation+Key.swift @@ -35,4 +35,8 @@ extension MAllocation: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(strategyID: "", assetID: "") + } } diff --git a/Sources/Model/Asset/MAsset+Key.swift b/Sources/Model/Asset/MAsset+Key.swift index 7a0de05..c66fa3d 100644 --- a/Sources/Model/Asset/MAsset+Key.swift +++ b/Sources/Model/Asset/MAsset+Key.swift @@ -33,4 +33,8 @@ extension MAsset: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(assetID: "") + } } diff --git a/Sources/Model/Cap/MCap+Key.swift b/Sources/Model/Cap/MCap+Key.swift index c380dcd..992fc94 100644 --- a/Sources/Model/Cap/MCap+Key.swift +++ b/Sources/Model/Cap/MCap+Key.swift @@ -36,4 +36,8 @@ extension MCap: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "", assetID: "") + } } diff --git a/Sources/Model/Holding/MHolding+Key.swift b/Sources/Model/Holding/MHolding+Key.swift index a7255a4..80b0099 100644 --- a/Sources/Model/Holding/MHolding+Key.swift +++ b/Sources/Model/Holding/MHolding+Key.swift @@ -39,4 +39,8 @@ extension MHolding: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "", securityID: "", lotID: "") + } } diff --git a/Sources/Model/Rebalance/Allocation/MRebalanceAllocation+Key.swift b/Sources/Model/Rebalance/Allocation/MRebalanceAllocation+Key.swift index 8091c23..845382a 100644 --- a/Sources/Model/Rebalance/Allocation/MRebalanceAllocation+Key.swift +++ b/Sources/Model/Rebalance/Allocation/MRebalanceAllocation+Key.swift @@ -36,4 +36,8 @@ extension MRebalanceAllocation: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "", assetID: "") + } } diff --git a/Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift b/Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift index b113141..c0f2b25 100644 --- a/Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift +++ b/Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift @@ -37,4 +37,8 @@ extension MRebalancePurchase: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "", assetID: "") + } } diff --git a/Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift b/Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift index ad314f8..7ff82d1 100644 --- a/Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift +++ b/Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift @@ -39,4 +39,8 @@ extension MRebalanceSale: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(accountID: "", securityID: "", lotID: "") + } } diff --git a/Sources/Model/Security/MSecurity+Key.swift b/Sources/Model/Security/MSecurity+Key.swift index 1475bff..aedc28d 100644 --- a/Sources/Model/Security/MSecurity+Key.swift +++ b/Sources/Model/Security/MSecurity+Key.swift @@ -33,4 +33,8 @@ extension MSecurity: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(securityID: "") + } } diff --git a/Sources/Model/Source/Meta/MSourceMeta+Key.swift b/Sources/Model/Source/Meta/MSourceMeta+Key.swift index 5265dba..ff75fef 100644 --- a/Sources/Model/Source/Meta/MSourceMeta+Key.swift +++ b/Sources/Model/Source/Meta/MSourceMeta+Key.swift @@ -33,4 +33,8 @@ extension MSourceMeta: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(sourceMetaID: "") + } } diff --git a/Sources/Model/Strategy/MStrategy+Key.swift b/Sources/Model/Strategy/MStrategy+Key.swift index 36eefe1..40808ed 100644 --- a/Sources/Model/Strategy/MStrategy+Key.swift +++ b/Sources/Model/Strategy/MStrategy+Key.swift @@ -33,4 +33,8 @@ extension MStrategy: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(strategyID: "") + } } diff --git a/Sources/Model/Tracker/MTracker+Key.swift b/Sources/Model/Tracker/MTracker+Key.swift index fe2a632..bd4dad3 100644 --- a/Sources/Model/Tracker/MTracker+Key.swift +++ b/Sources/Model/Tracker/MTracker+Key.swift @@ -33,4 +33,8 @@ extension MTracker: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(trackerID: "") + } } diff --git a/Sources/Model/Transaction/MTransaction+Key.swift b/Sources/Model/Transaction/MTransaction+Key.swift index 0e78303..f46c336 100644 --- a/Sources/Model/Transaction/MTransaction+Key.swift +++ b/Sources/Model/Transaction/MTransaction+Key.swift @@ -57,4 +57,8 @@ extension MTransaction: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(action: .miscflow, transactedAt: Date.init(timeIntervalSinceReferenceDate: 0), accountID: "", securityID: "", lotID: "", shareCount: 0, sharePrice: 0) + } } diff --git a/Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift b/Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift index b5ae8bf..9167c7f 100644 --- a/Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift +++ b/Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift @@ -39,4 +39,8 @@ extension MValuationCashflow: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(transactedAt: Date.init(timeIntervalSinceReferenceDate: 0), accountID: "", assetID: "") + } } diff --git a/Sources/Model/Valuation/Position/MValuationPosition+Key.swift b/Sources/Model/Valuation/Position/MValuationPosition+Key.swift index d52488d..f8fa679 100644 --- a/Sources/Model/Valuation/Position/MValuationPosition+Key.swift +++ b/Sources/Model/Valuation/Position/MValuationPosition+Key.swift @@ -39,4 +39,8 @@ extension MValuationPosition: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(snapshotID: "", accountID: "", assetID: "") + } } diff --git a/Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift b/Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift index f28c3a7..c36b4f9 100644 --- a/Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift +++ b/Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift @@ -33,4 +33,8 @@ extension MValuationSnapshot: AllocKeyed { public var primaryKey: Key { Key(self) } + + public static var emptyKey: Key { + Key(snapshotID: "") + } }