Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8805065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:46:01+00:00 2026-06-14T01:46:01+00:00

I have a drawing app where paths are saved when the user draws and

  • 0

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]];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:46:03+00:00Added an answer on June 14, 2026 at 1:46 am

    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:

    NSAssert([arr3 count]>=[newpaths count], @"newpaths is longer than arr2");
    

    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:

    NSAssert(index<[arr3 count], @"Index out of bounds");
    NSMutableArray *arr3 = [defaults objectForKey:[NSString stringWithFormat:@"%@BrushColours%@", currentid, pageno]];
    self.brushColor = [NSKeyedUnarchiver unarchiveObjectWithData:[arr3 objectAtIndex:index]];
    

    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:

    id obj= [newpaths objectAtIndex: index];
    NSUInteger validIndex=[arr3 indexOfObject: obj];
    if(validIndex!= NSNotFound)
        self.brushColor = [NSKeyedUnarchiver unarchiveObjectWithData:[arr3 objectAtIndex: validIndex]];
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drawing app where the user can draw lines with their finger,
I am doing a Drawing App. I have saved the color fill image as
I have a vector drawing app where users can draw lines using multiple quadratic
We have an HTML5 drawing app where users can draw lines using a pencil
I have a question about making a drawing app for Android. What is the
Hi I am trying out drawing app and have a problem when it comes
I am making a drawing app for iOS and I have the following classes:
I have a drawing app in which I want to implement UNDO feature so
I am working on a iPad drawing app.. were i have a UIView class
I have a fullscreen drawing app that disables the title and status bars using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.