mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-12 08:13:26 +01:00
[Widgets]: Enhanced to isolate operations from multiple views of same widget type
This commit is contained in:
30
SideStore/Utils/datastructures/SingletonGenericMap.swift
Normal file
30
SideStore/Utils/datastructures/SingletonGenericMap.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// SingletonGenericMap.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Magesh K on 10/01/25.
|
||||
// Copyright © 2025 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
class SingletonGenericMap{
|
||||
static var shared = SingletonGenericMap()
|
||||
private var pageInfoMap: [AnyHashable: Any] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
func setPageInfo<T: Hashable, U>(for key: T, value: U?) {
|
||||
pageInfoMap[key] = value
|
||||
}
|
||||
|
||||
func getPageInfo<T: Hashable, U>(for key: T) -> U? {
|
||||
return pageInfoMap[key] as? U
|
||||
}
|
||||
|
||||
func popPageInfo<T: Hashable, U>(for key: T) -> U? {
|
||||
return pageInfoMap.removeValue(forKey: key) as? U
|
||||
}
|
||||
|
||||
func clearAll() {
|
||||
pageInfoMap.removeAll()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user