2

I have an NS Cache, and I would like to get ALL of the objects that it stores as an array. The keys will be needed as well. Everything I have read says that I should be able to basically treat it like a dictionary, but I get compiler errors when I try:

var tinyCache: NSCache<NSString, NSString> = NSCache<NSString, NSString>() let keys = tinyCache.keys let values = tinyCache.values

The compiler error tells me that NS Cache doesn't have a member 'keys' or 'values' I have looked through the documentation here and can't find any indication of how to get the keys or values:

https://developer.apple.com/reference/foundation/nscache

So how do I get all of the keys and values from the cache?

I have looked at all of the other SO questions and haven't found a suitable solution for Swift

Mizmor
  • 1,391
  • 6
  • 21
  • 43
  • I don't think that NSCache offers such a method. Why do you need it? – Martin R Apr 19 '17 at 16:43
  • I am caching the results of API calls to a Rails Server. When a user makes a GET call to an Index endpoint, multiple items are returned. I want the cache to be able to give back a specific item in addition to ALL of the items pulled down by the Index call. – Mizmor Apr 19 '17 at 16:46
  • @MartinR, it would really help with debugging multithreaded projects. – ScottyBlades Jul 17 '22 at 02:27

0 Answers0