Skip to content

Commit

Permalink
added emptyKey property to support pickers (#4)
Browse files Browse the repository at this point in the history
* added emptyKey property to support pickers
  • Loading branch information
reedes authored Oct 24, 2021
1 parent 46b0c39 commit 0910003
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
```

Expand Down
1 change: 1 addition & 0 deletions Sources/Core/AllocKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public protocol AllocKeyed: Hashable {
associatedtype Key: Hashable, Codable

var primaryKey: Key { get }
static var emptyKey: Key { get }
}

public extension AllocKeyed {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/Account/MAccount+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MAccount: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Allocation/MAllocation+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ extension MAllocation: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(strategyID: "", assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Asset/MAsset+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MAsset: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Cap/MCap+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ extension MCap: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "", assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Holding/MHolding+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ extension MHolding: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "", securityID: "", lotID: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ extension MRebalanceAllocation: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "", assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Rebalance/Purchase/MRebalancePurchase+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ extension MRebalancePurchase: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "", assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Rebalance/Sale/MRebalanceSale+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ extension MRebalanceSale: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(accountID: "", securityID: "", lotID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Security/MSecurity+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MSecurity: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(securityID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Source/Meta/MSourceMeta+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MSourceMeta: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(sourceMetaID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Strategy/MStrategy+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MStrategy: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(strategyID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Tracker/MTracker+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MTracker: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(trackerID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Transaction/MTransaction+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Valuation/Cashflow/MValuationCashflow+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Valuation/Position/MValuationPosition+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ extension MValuationPosition: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(snapshotID: "", accountID: "", assetID: "")
}
}
4 changes: 4 additions & 0 deletions Sources/Model/Valuation/Snapshot/MValuationSnapshot+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ extension MValuationSnapshot: AllocKeyed {
public var primaryKey: Key {
Key(self)
}

public static var emptyKey: Key {
Key(snapshotID: "")
}
}

0 comments on commit 0910003

Please sign in to comment.