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 173257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:18:42+00:00 2026-05-11T13:18:42+00:00

After four weeks of learning Objective-C for the iPhone, my first useful application is

  • 0

After four weeks of learning Objective-C for the iPhone, my first useful application is almost finished. However, I still need to save several instance variables whenever the current view is changed and to reload them when the view is reopened.

I have no trouble loading variables with basic C types like int and BOOL, but am having difficulty with a linked list made of Objective-C objects.

The linked list consists of memory accessed by three pointers: startPointer, currPointer, and endPointer. Each element consists of a last pointer, a next pointer, a pointer to a nested linked list (nestedPtr), and some variables.

My first attempt was to do the following in the loading code:

//dataStorageObj will contain the values to be loaded dataStorageObj = [[DataSaver alloc] init]; NSData *data =[[NSMutableData alloc] initWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@'Archive']]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; dataStorageObj = [unarchiver decodeObjectForKey:@'KeyForViewA']; [unarchiver finishDecoding]; //**************************** //Simple variables loaded here //**************************** //DataSaver is a class with methods to retrieve its instance variables //The methods are named after the values they retrieve startPointer = [dataStorageObj startPointer]; currPointer = [dataStorageObj currPointer]; endPointer = [dataStorageObj endPointer]; [unarchiver release]; [data release]; 

I placed a debug point at the end and all of the variables had the correct values. Actually accessing the values in the code (doing so in the console worked) resulted in EXC_BAD_ACCESS messages.


Next, I changed the linked list loading lines to the following:

startPointer = [[PointerClass alloc] initPointerFromList:[dataStorageObj startPointer]]; currPointer = [[PointerClass alloc] initPointerFromList:[dataStorageObj currPointer]]; endPointer = [[PointerClass alloc] initPointerFromList:[dataStorageObj endPointer]]; 

The initPointerFromList method:

-(PointerClass *)initPointerFromList:(PointerClass *)theList {     last = theList.last;     nestedPointer = [[NestedPointerClass alloc] initNestedPointerFromList:theList.nestedPointer];     //****************************************     //Other variables loaded from theList here     //****************************************     if (theList.next != nil)     {         next = [[PointerClass alloc] initPointerFromList:theList.next];     }      return self; } 

The problem now was that the pointers were all pointing to individual linked lists, so I wrote methods to retrieve the start and end locations of the linked list referred to by currPointer:

currPointer = [[PointerClass alloc] initPointerFromList:[dataStorageObj currPointer]]; endPointer = [currPointer lastElement]; startPointer = [currPointer firstElement]; 

My question is threefold:

  1. Is it necessary to use methods such as initPointerFromList to allocate memory for a loaded linked list?
  2. Is there a more efficient way to maintain the relationship between currPointer, endPointer, and startPointer than by searching through the list using the lastElement and firstElement methods?
  3. Is there something wrong with the techniques behind the loading code I have presented? Without it, I have no problems; with it, I still get BAD_ACCESS messages. I want to know if these messages are tied to the loading code or if to the way I have handled object allocation throughout the rest of my application.

Thanks in advance!

  • 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. 2026-05-11T13:18:43+00:00Added an answer on May 11, 2026 at 1:18 pm

    Pointers tend to be a sore point of archives, as you’ve discovered. Is it possible for you to use NSMutableArray for your storage requirements, as this might simplify matters for you.

    http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047

    If you’re not going to use NSMutableArray, you probably want to create a container class that responds to the encodeWithCoder message, and encode the list that way. You’re not going to store the pointers, but rather use them to walk your container, and archive it in some deterministic order.

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

Sidebar

Related Questions

After reading the Head First Design Patterns book and using a number of other
after trying to solve the problem without and with help I'm still stuck. My
What do software engineers encounter after another stressfull release? Well, the first thing we
I have four DB tables in an Oracle database that need to be rewritten/refreshed
I have four branches (master, b1, b2, and b3). After I worked on b1-b3,
After the suggestion to use a library for my ajax needs I am going
After reading this question , I was reminded of when I was taught Java
After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no
After being told by at least 10 people on SO that version control was
After lots of attempts and search I have never found a satisfactory way to

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.