I have this: NSMutableArray *myMArray and I have 2 IBaction, (insert) & (remove). I have worked out everything so when the user hits (insert) an object, it will be inserted to myMarray. My (remove) action has [myMArray removeLastObject].
My problem, which should be obvious now, is that when I insert lets say 5 objects, by hitting (insert) 5 times and then hitting (remove) 6 times , the thing will crash because the array is empty.
I understand what the problem is, but can’t find a solution to implement when the user hits (remove) and the index in myMArray is at 0 to stop the app from crashing.
I appreciate your help.
Just check the array size before calling
removeLastObjecton it.