Creating NSArray – EXC_BAD_ACCESS?-Collection of common programming errors

When I try to create the NSArray purchasedTimeArray, I get a crash EXC_BAD_ACCESS

NSString *blank = @"";
NSArray *purchasedTimeArray = [[NSArray alloc] initWithObjects:
                                   timeRemainingTitle, blank, @"imagename.png", blank, description, 4, nil];

And yes, timeRemainingTitle and description still exist in memory. They are both NSStrings.

  1. Use the new Objective-C syntax:

    NSArray *purchasedTimeArray = @[ timeRemainingTitle, blank, @"imagename.png", blank, description, @4 ];
    

    Two benefits:

    1. Much easier to write.
    2. No need for nil terminator and if one of the other values are nil in value, all the objects still end up in the array.

    As noted in the comments, the @4 syntax translates to [NSNumber numberWithInt:4].