Skip to content

Commit

Permalink
⭐️ Impl: RNIObjectMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Mar 30, 2023
1 parent 2773225 commit 882e1ab
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ios/src_library/Helpers+Utilities/RNIObjectMetadata.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// RNIObjectMetadata.swift
// react-native-ios-modal
//
// Created by Dominic Go on 3/31/23.
//

import Foundation

fileprivate let RNIObjectMetadataMap = NSMapTable<AnyObject, AnyObject>(
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
}
};
};

0 comments on commit 882e1ab

Please sign in to comment.