Solution for Ch 16 Bronze Challenge in Xcode 9.3

//  ImageStore.swift

class ImageStore {
...
  func imageURL(forKey key: String) -> URL {
    let documentsDirectories = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let documentDirectory = documentsDirectories.first!
    return documentDirectory.appendingPathComponent(key).appendingPathExtension("png")
  }

  func setImage(_ image: UIImage, forKey key: String) {
    cache.setObject(image, forKey: key as NSString)

    let url = imageURL(forKey: key)
    if let data = UIImagePNGRepresentation(image) {
      try? data.write(to: url, options: [.atomic])
    }
  }
}