3

The Contents.json file of an asset catalog's image looks like this:

{
  "images" : [
    {
      "idiom" : "universal",
      "filename" : "Hero-0-Recharging.png",
      "scale" : "1x"
    },
    {
      "idiom" : "universal",
      "filename" : "Hero-0-Recharging@2x.png",
      "scale" : "2x"
    },
    {
      "idiom" : "universal",
      "filename" : "Hero-0-Recharging@3x.png",
      "scale" : "3x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

Let's suppose that I want to add additional info to this image's json data, which is meant to be accessed at runtime. If I modify the json text data (e.g. by adding the "color" attribute to every version of the image), is there a way to read it at runtime?

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • It's already saved automatically by Xcode. I just want to modify it. – Ramy Al Zuhouri Jul 24 '17 at 20:51
  • Why not create a different file? Why do you want to modify that file?Furthermore, I don't think it's possible, per-se, you can read the contents but not write to it at run time - https://stackoverflow.com/questions/33618452/adding-json-as-asset-and-reading-it – Anjan Biswas Jul 24 '17 at 20:55
  • I could create another file, but it would be handy to use the already existent Contents.json instead of creating another file. – Ramy Al Zuhouri Jul 24 '17 at 20:58
  • 1
    I get what you're saying, but if you see the `Contents.json` file is an internal file created by Xcode which is not accessible through IB. So I am not really sure what would happen if you want to force update that file somewhow since afterall it contains metadata about the image assets for your file. I would recommend creating a new file using the contents of the `Contents.json` file at run time if that's what you want to do. – Anjan Biswas Jul 24 '17 at 21:02
  • I need to write that file at pre-runtime (I just navigate to the file using Finder and manually modify it), and read it at runtime. – Ramy Al Zuhouri Jul 24 '17 at 21:06

0 Answers0