127
TableViewApplication[1458:70b] CUICatalog: Invalid asset name supplied: (null), or invalid scale factor: 2.000000

Screenshot added

Getting this warning while working with TableViewController. How to rectify this error and which block is affected?

Jayprakash Dubey
  • 32,447
  • 16
  • 161
  • 169
manish singh
  • 1,273
  • 2
  • 9
  • 4

12 Answers12

256

This one appears when someone is trying to put nil in [UIImage imageNamed:]

Add symbolic breakpoint for [UIImage imageNamed:]Symbolic breakpoint example

Add $arg3 == nil condition on Simulator, $r0 == nil condition on 32-bit iPhone, or $x2 == nil on 64-bit iPhone.

Run your application and see where debugger will stop.

P.S. Keep in mind this also happens if image name is empty string. You can check this by adding [(NSString*)$x2 length] == 0 to the condition.

Alexander Vasenin
  • 11,028
  • 3
  • 39
  • 65
tt.Kilew
  • 5,614
  • 2
  • 30
  • 49
  • Very nice approach! I always forget about symbolic breakpoints. – mAu May 13 '15 at 12:59
  • 7
    This is a clever approach. It looks like my nil image is somewhere in my nib, so it's not going through `UIImage imageNamed:`, but I'm saving this breakpoint nonetheless. – cbowns May 16 '15 at 00:01
  • 9
    I didn't know about the `$arg3` syntax for conditional breakpoints. Where can I learn more? – Zev Eisenberg Jun 02 '15 at 21:35
  • Great solution, thank you. Is it possible to add condition for result, not for the argument? – derpoliuk Oct 08 '15 at 17:18
  • 3
    Not sure to understand why it doesn't work for me, always returning ```error: use of undeclared identifier '$arg3'```. Did I miss something? – Ben Nov 13 '15 at 12:46
  • 6
    i keep getting: Stopped due to an error evaluating condition of breakpoint 23.1: "$r0 == nil" Couldn't parse conditional expression: error: use of undeclared identifier '$r0' error: 1 errors parsing expression – sudoExclaimationExclaimation Nov 24 '15 at 20:22
  • Then what? nothing happen to tell me what asset is that! – hasan Feb 13 '16 at 14:43
  • I set condition: (int)[*(id*)($esp+12) length] == 0 – CHiP-love-NY Feb 19 '16 at 12:24
  • 1
    $arg3 == nil (not $r0 == nil) work for me for iPhone device run – Artem Illarionov Feb 13 '17 at 11:17
  • 8
    In my case the image name string was empty, so checking the arg3 length worked for me. `(int)[$arg3 length] == 0` – Matthew Korporaal Mar 15 '17 at 02:31
  • 3
    If you are having difficulty finding the right register create the breakpoint without the condition, then in lldb run the following `register read -f d`. Look through the printed registers to see which one contains an image name, then use that register in your breakpoint condition. – Josh Bernfeld Mar 20 '19 at 02:28
64

This error (usually) happens when you try to load an image with [UIImage imageNamed:myImage] but iOS is not sure if myImage is really a NSString and then you have this warning.

You can fix this using:

[UIImage imageNamed:[NSString stringWithFormat:@"%@", myImage]]

Or you can simply check for the length of the name of the UIImage:

if (myImage && [myImage length]) {

    [UIImage imageNamed:myImage];
}
Fabio
  • 1,519
  • 17
  • 32
  • 2
    In case anyone made the same mistake I did, I was trying to update a UIButton's background image to be removed (no image at all) and so I changed my UIImage name from a string to just "", which caused the error. By removing the entire UIImage(named: "") and replacing it with nil, the error disappeared. – Dave G Aug 24 '15 at 17:13
  • @DaveG You sir, saved me hours. Thankyou for the comment! – Jeff Sep 01 '16 at 00:38
22

Since the error is complaining that the name you gave is (null), this is most likely caused by calling [UIImage imageNamed:nil]. Or more specifically, passing in a variable hasn't been set, so it's equal to nil. While using stringWithFormat: would get rid of the error, I think there's a good chance it's not actually doing what you want. If the name you supply is a nil value, then using stringWithFormat: would result in it looking for an image that is literally named "(null)", as if you were calling [UIImage imageNamed:@"(null)"].

Something like this is probably a better option:

if (name) {
    UIImage *image = [UIImage imageNamed:name];
} else {
    // Do something else
}

You might want to set a breakpoint in Xcode on that "Do something else" line, to help you figure out why this code is getting called with a nil value in the first place.

robotspacer
  • 2,542
  • 1
  • 23
  • 46
17

In Xcode 6.4, this seems to occur when using "Selected Image" for a tab bar item in the storyboard, even if it's a valid image.

enter image description here

This doesn't actually seem to set the selected state image anyway, so it needs to be defined in User Defined Runtime Attributes, and removed from the SelectedImage attribute of the Tab Bar Item

enter image description here

ginchly
  • 365
  • 4
  • 8
  • 1
    Thank you for that! These error/warning messages were driving me nuts! I can't figure out why Apple doesn't either get rid of the Tab Bar Item "Selected Image" pulldown in IB or fix it so it works correctly. – wcochran Sep 01 '15 at 04:04
4

In my case i was passing [UIImage imageNamed:@""] which caused me to show the warning. Just add breakpoints to all the lines where you have used imageNamed and the debug the line where you find the warning.

Rahul Mathur
  • 862
  • 1
  • 7
  • 20
  • I am also using `[UIImage imageNamed:@""]` . How did you fix it? – Julfikar Nov 09 '17 at 08:42
  • [aButton setImage:nil forState:UIControlStateNormal] – Hahnemann Mar 08 '18 at 21:00
  • Other than using an `if` to test if the image name is not an empty string, or using a default "noImage" image, how do you display no image when no applicable name applies and the Assets do not contain a "noImage" image? – gone Apr 14 '20 at 09:45
2

This happened to me after a storyboard was split into several (the actual change happened when I was on holidays, so I don't know exactly how it was done).

After inspecting the XML of the storyboards, I found that an image reference which previously had pointed to "bottomBar" in the assets catalogue instead pointed to imageView:fFo-1g-jzs:image.

At the end of the XML file under the <resources> tag was tag named <image name="imageView:fFo-1g-jzs:image"> containing a big mutableData blob.

After resetting the image reference in the storyboard and removing the blob, the error went away.

idrougge
  • 463
  • 3
  • 11
1

I have just fixed this error. Just check the usage of the [UIImage imageNamed:(NSString*) imageName] function. If the imageName is nil, then error occurs.

Cesare
  • 8,326
  • 14
  • 64
  • 116
passwind
  • 139
  • 5
1

You are supplying some invalid image name, so need to validate before putting it you can do any of the above ways whichever make sense for your code or like

if (iconImageName && [iconImageName length])
{

    [UIImage imageNamed:iconImageName];
}
else
{
     iconImageName.hidden = YES;
}

Hope it will help!!!!

Aks
  • 4,339
  • 1
  • 33
  • 32
0

The Reason to the error is passing a nil value to the "imageNamed:" method. To avoid this, you can hide your imageView when you try to pass the nil value. The chances may occur in reusing the imageViews in UITableView or may be in scrollViews.

I avoided the warning with the below check :

UIImageView *your_image_view;
NSString *imageName;
if(imageName && imageName.length){
 your_image_view.hidden = NO;
 your_image_view.image = [UIImage imageNamed:imageName];
}
else {
 your_image_view.hidden = YES;
}
Bharath
  • 189
  • 1
  • 8
0

I got this warning when I load image use [[UIImage imageNamed:normalStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], than, I change to [UIImage imageNamed:normalStr], warning was gone.

Meilbn
  • 552
  • 6
  • 8
0

One approach is do class method swizzling to replace [UIImage imageNamed:] with your own implementation, then check the image name in your implementation. See the following:

How to swizzle a class method on iOS?

I implemented this in my UIImage(Debug) category:

+ (UIImage *)db_imageNamed:(NSString *)imageName {
    if ([imageName length] == 0) {
        NSLog(@"breakpoint here");
    }
    return [self db_imageNamed:imageName];  // not a recursive call here after swizzling
}

You might want to swizzle [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] as well.

Community
  • 1
  • 1
Haoxin Li
  • 61
  • 3
-1

Maybe you can use this to confirm the "imageName" is not a "nil";Then you will leave away this warning.

 if (imageName) {
    self.imageView.image = [UIImage imageNamed:imageName];
 }