I have a drawing app where paths are saved when the user draws and loaded back in when the user closes and re-opens the app.
I am adding objects (the brush colours) to an NSMutableArray then saving them like so:
// Adding object to NSMutableArray (this is in touchesMoved)
NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:self.brushColor];
[self.brushColours addObject:colorData];
// Saving array (this is in touchesEnded)
[defaults setObject:self.brushColours forKey:[NSString stringWithFormat:@"%@BrushColours%@", currentid, pageno]];
[defaults synchronize];
That’s all fine and dandy, but when I try to load the paths back in and set their colours, this happens:

Why is this happening?
Edit: I’m loading the colours back in like this (this is in a for loop for each path):
NSMutableArray *arr3 = [defaults objectForKey:[NSString stringWithFormat:@"%@BrushColours%@", currentid, pageno]];
self.brushColor = [NSKeyedUnarchiver unarchiveObjectWithData:[arr3 objectAtIndex:index]];
index is the index of the object path in newpaths, but you are using this index to access to an object in arr3, not in newpaths.Are you sure that the newpaths array have the same length or arr3? Do some assertions before doing that:
This before the loop.Probably this assertion will be not true because as your exception says, index is out of arr3 bounds, unless you somehow modify the arr3 array inside the loop.
Test arr3 before accessing to it’s elements:
For sure an assertion will fail and you’ll know more exactly (but not totally exactly) what’s wrong.By investigating again you could get the reason of the bug (also post more code if you can’t achieve this alone).
EDIT
Alternative solution: It’s not clear what you’re trying to do, but I suppose that you want to find that object in arr3 and to unarchive it.
So you can use indexOfObject:
PS: Anyway you could directly unarchive obj, unless the objects result equal (isEqual method) but after the comparison you somehow changed the state of the object.