ios - Why does this loop cause a crash if nothing is found in the array -
i'm totally lost , not sure how phrase question. have loop can see below. if if statement within loop proves true indexpath assigned value, loop completes (there 49 objects in _samplepicture s array)and enters if (found) , loads found data. if the condition not true , nothing found instead of entering if(!found) app crashes. have tried various structures of current coding scheme. removed loop , entered if(!found) supposed to. (ooooodddddddd) this statement in viewdidload , directly above (the if statement not viewdidload ) if statement determines contents of _samplepictures . it may useful know images in array define this: #define img_71 [uiimage imagenamed:@"imagename.jpg"] the array structured in way: _samplepictures = @[@{@"image": img_71, @"title" : @"title of item", @"description" : @"complete description of item"}]; if (fromkitinstructions) { int = 0; nsindexpath *indexpath; ...