Question

The Contents.json describing the image set "BG_Email_Textfield.imageset" must start with a top level dictionary.

how we could solve this ?

Was it helpful?

Solution

This often occurs when the merge conflicts, you can open the YourImageName.imageset folder in Finder and edit Contents.json, remove the code conflict.

In my case, I merge conflicting files like this:

{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x"
    },
    {
      "idiom" : "universal",
      "scale" : "2x",
      "filename" : "BodySelfieTabbarItem@2x.png"
    }
  ],
  "info" : {
    "version" : 1,
<<<<<<< HEAD
    "author" : "xcode",
    "template-rendering-intent" : "original"
=======
    "author" : "xcode"
>>>>>>> f15823d967d53508370cfcbd708e15ee2fad328e
  }
}

After removing the code conflicts like this:

{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x"
    },
    {
      "idiom" : "universal",
      "scale" : "2x",
      "filename" : "BodySelfieTabbarItem@2x.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode",
    "template-rendering-intent" : "original"
  }
}

OTHER TIPS

When you goto "xcassets" there your images are unsigned. make new imageset and assign images to that one and delete the unsigned imageset. I hope your problem resolve.

If you use Xcode to add a single image to your project as an image set, Xcode creates a subdirectory containing two files- the image and a Contents.json file. You can see this in Finder. In your Xcode project directory open Images.xcassets. For example Images.xcassets could have a subdirectory myImage.imageset with myImage.png and a Contents.json similar to

{
  "images" : [
    {
      "idiom" : "universal",
      "scale" : "1x",
      "filename" : "myImage.png"
    },
    {
      "idiom" : "universal",
      "scale" : "2x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

You can specify another image for 2x resolution. If your project does not contain a directory and Contents.json file similar to this, it may be easiest to use Xcode to add the image set. In Xcode project navigator, if you select Images.xcassets a pane appears with a small "+" at the bottom to "add a group or image set".

References
https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/AddingImageSets/AddingImageSets.html
https://www.iphonelife.com/blog/31369/unleash-your-inner-app-developer-managing-images-xcode-5-asset-catalogs

I remove all contents in Images.xcassets, and then in xcode choose not use asset catalog.

A bit late yes, but I just came across this question and thought it may still be of some use to either the OP or the next reader having the same issue.

The answer by Vincent is definitely a solution, assuming that the OP is indeed using version control and there is a merge conflict. The OP has suggested neither.

The answer by lbsweek is not really a solution if asset catalogs are the only option and furthermore follows the dreaded 'why are you doing it this way...do it this way instead' paradigm.

So I will expand on what was said by beepscore. Although the answer by beepscore explains what a Contents.json file is and how it relates to images added to a catalog, it does not explain what might be causing the problem described by the OP and neither does it explain how to solve it.

This error will most likely be shown when the Contents.json file cannot be parsed. This may be due to something obvious, such as merge conflict characters being placed inside the file as described by Vincent, or it may be something more subtle, such as an encoding issue (funny invisible characters, etc).

One way to correct this issue is by making a backup up of the .xcassets folder in finder, getting Xcode to produce it via the IDE and then modify the generated Contents.json file using the backed up version as a guide.

For me it turned out that Mac OS TextEdit was using smart double quotes instead of regular double quotes and XCode couldn't parse the Constents.json file after I manually edited it. So I fixed this under Mac OS Settings->Keyboard->Text uncheck "use smart quotes and dashes" and in the "for Double Quotes" options select the appropriate double quote that matches what XCode expects. For me that was the bottom choice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top