//
//  BSUObjectCache.m
//  BlueStack
//
//  Created by Nagib Bin Azad on 11/21/22.
//

#import <Foundation/Foundation.h>

/// A thread-safe cache to hold onto objects while Unity is still referencing them.
@interface BSUObjectCache : NSObject

+ (nonnull instancetype)sharedInstance;

/// Reference to self for backwards API compatibility.
@property(nonatomic, readonly, nonnull) BSUObjectCache *references;

/// NSMutableDictionary methods for setting and retrieving objects.
- (void)setObject:(nullable id)object forKey:(nonnull NSString *)key;
- (nullable id)objectForKey:(nonnull NSString *)key;
- (void)setObject:(nullable id)obj forKeyedSubscript:(nonnull NSString *)key;
- (nullable id)objectForKeyedSubscript:(nonnull NSString *)key;
- (void)removeObjectForKey:(nonnull NSString *)key;

@end

@interface NSObject (BSUOwnershipAdditions)

- (nonnull NSString *)BSU_referenceKey;

@end
