• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Saving & Loading Issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Saving & Loading Issue


  • Subject: Saving & Loading Issue
  • From: Wayne Lau <email@hidden>
  • Date: Tue, 5 Oct 2004 16:15:00 -0700

Hello,

I'm trying to implement saving and loading functionality into my program using these two methods originally defined in my document class:

- (NSData *)dataRepresentationOfType:(NSString *)aType
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType

Inside the first method, here is my source:

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSLog(@"About to save data");


// end editing
[arrayController commitEditing];


// create an NSData object from myArray
return [NSKeyedArchiver archivedDataWithRootObject:myArray];

return nil;
}

As you can see, the objective of my saving\loading is to save\load the contents of an array (currently the object being pointed to by the contentsArray of my NSArrayController).

And during the execution of the program, when this fxn is called automatically when I go file->save, the contents of my array are stored in the saved file as expected. I've setup all the encoding\decoding methods within my model class as well to know how to encode\decode itself.

The problem is when I try to load the data back in. Two scenarios result:

Scenario A: Say I save the file in my current document window, and then remove a few things from the array. When I try and open the previously saved file, nothing happens. It just goes from the open screen, back to my document window without any changes.

Scenario B: If I open a new document window, and go File->Open and choose the previously saved file. The program crashes giving me an error: "Executable “CustomApp” has exited due to signal 11 (SIGSEGV)."

And using the debugger, i've pinpointed it to this line of crashing which is in my second method:

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSLog(@"About to read data");


NSMutableArray *newArray;

// CRASHES at this line below when it tries to unarchive :(
--> newArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];


if (newArray == nil) {
return NO;
}
else {
[self setArray: newArray];
return YES;
}
}


Thank you for reading. I hope someone has some advice or suggestion they can give me to remedy this problem please.

Wayne
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: TIFFs produced by TIFFRepresentation not portable?
  • Next by Date: Re: Binding/KVC : valueForKey: and NSDictionary (was: valid accessor for framework objects. (was: implicit and explicit invocation of description method))
  • Previous by thread: Finding the active Text View.
  • Next by thread: saving image format problem of NSBMPFileType
  • Index(es):
    • Date
    • Thread