2

What is the simplest way to persistently store a NSCache filled with NSImages? I'm not looking for Core Data, which seems like overkill for just storing a dictionary with images.

houbysoft
  • 32,532
  • 24
  • 103
  • 156

1 Answers1

1

If all you have is a set of pictures, I'd simply get a path from the user and use NSImage's TIFFRepresentation to get instances of NSData for each picture, which can then be written to the path using NSFileManager and NSFileHandle.

If you have info accompanying the images, like tags, I'd put that, along with identifying titles for the images, in an array of dictionaries. Then you can use NSArray's writeToFile:atomically: method to write out a plist.

Wienke
  • 3,723
  • 27
  • 40
  • `NSCache` doesn't have a `writeToFile`-like method, and as far as I can see there's no way to convert it to a `NSDictionary`. – houbysoft Jul 29 '12 at 14:47
  • Your archival routine would get the objects out of the cache and put them into dictionaries, which you would put into an array, upon which you would then call `writeToFile`. – Wienke Jul 29 '12 at 19:22
  • The problem is as far as I can see there's no method that gets the objects out of a NSCache apart from the method to get an object for a given key. Therefore the only way would be to keep a separate array of the NSCache keys, but I asked this question because i thought there would be a better way... – houbysoft Jul 29 '12 at 19:49