From 882e1abff2ebdbbc4be792d16365469b58ccf05f Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 31 Mar 2023 01:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`RNIObjectMetadata?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helpers+Utilities/RNIObjectMetadata.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ios/src_library/Helpers+Utilities/RNIObjectMetadata.swift diff --git a/ios/src_library/Helpers+Utilities/RNIObjectMetadata.swift b/ios/src_library/Helpers+Utilities/RNIObjectMetadata.swift new file mode 100644 index 00000000..641d261e --- /dev/null +++ b/ios/src_library/Helpers+Utilities/RNIObjectMetadata.swift @@ -0,0 +1,35 @@ +// +// RNIObjectMetadata.swift +// react-native-ios-modal +// +// Created by Dominic Go on 3/31/23. +// + +import Foundation + +fileprivate let RNIObjectMetadataMap = NSMapTable( + keyOptions: .weakMemory, + valueOptions: .strongMemory +); + +public protocol RNIObjectMetadata: AnyObject { + associatedtype T: AnyObject; + + var metadata: T? { get set }; +}; + +public extension RNIObjectMetadata { + var metadata: T? { + set { + if let newValue = newValue { + RNIObjectMetadataMap.setObject(newValue, forKey: self); + + } else { + RNIObjectMetadataMap.removeObject(forKey: self); + }; + } + get { + RNIObjectMetadataMap.object(forKey: self) as? T + } + }; +};