Q:

NSArray code not being run

I can't figure this one out, hopefully someone can help.
This is the code in my ViewController.h file.
{
NSArray *bgImages;
int currentBackground;
bool hasShrunk;
bool hasMoved;

CGAffineTransform translate;
CGAffineTransform sizeShrink;
CGAffineTransform sizeGrow;
}

Here is some of my code in the ViewController.m file.
- (void)viewDidLoad {
hasMoved = NO;
hasShrunk = NO;
currentBackground = 0;

bgImages = [[NSArray alloc] initWithObjects:
        [UIImage imageNamed:@"WallPaper_01.png"],
        [UIImage imageNamed:@"WallPaper_02.png"],
        [UIImage imageNamed:@"WallPaper_03.png"],
        [UIImage imageNamed:@"WallPaper_04.png"],
        [UIImage imageNamed:@"WallPaper_05.png"],
        nil];

sizeShrink = CGAffineTransformMakeScale(.25,.25);
sizeGrow = CGAffineTransformMakeScale(1,1);

_myBackground.image = [bgImages objectAtIndex:currentBackground];
}

Here is the issue.  This code and the entire project run fine on the simulator, no issues.  When I change the output to an actual iPhone device it fails.  The code is failing on the allocation of the array called bgImages.  If I place a breakpoint on viewDidLoad and step into it line by line, it executes up to the array allocation line and then jumps over it.  When it then attempts to execute the line:
_myBackground.image = [bgImages objectAtIndex:currentBackground];

it will fail because the array is empty.  I don't understand how this can work in the simulator but not on the actual device.  The code does not look incorrect but I am at my wits end trying to understand why it behaves this way.  Have I coded it incorrectly?

A:

You're getting a problem because the array doesn't have any elements in it. One possibility is that all of the [UIImage imageNamed:...] calls are returning nil. Break one of these out as a separate variable, e.g.
UIImage *firstImage = [UIImage imageNamed:@"WallPaper_01.png"];

and set a breakpoint on that line to make sure that the image is being initialized correctly. If it isn't, one possible reason is that you have the 2x version (WallPaper_01@2x.png) but not the 1x version, or vice versa.
Edit: As @rdelmar notes, another possible reason is that, since Mac OS X uses (by default) a case-insensitive filesystem but iOS uses a case-sensitive filesystem, you're using the wrong filename, but you're only seeing a problem on iOS because OS X doesn't care that the filename isn't exactly right.

