NSKeyedUnarchiver

Parrish Myers <[email protected]>
Newsgroups gmane.comp.lib.gnustep.user
Message-ID <[email protected]>
Can someone please help... this doesn't make sense:

The following code should print the NSMutableArray twice... but only does
once... the NSKeyedUnarchiver doesn't seem to work on windows...

------------------------------------

#import <Foundation/Foundation.h>

void printArray(NSMutableArray *anArray)
{
  int length = [anArray count];
  int i;
  for (i = 0; i < length; i++) {
    NSLog(@"object %d : %@", i, [anArray objectAtIndex:i]);
  }
}

int main(int argc, const char **argv)
{
  int i;
  NSData *d1, *d2;
  BOOL result;
  NSMutableArray *theArray, *newArray;

  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  theArray = [[NSMutableArray alloc] init];

  for (i = 0; i < 100; i++) {
    [theArray addObject:[NSNumber numberWithInt:i]];
  }

  printArray(theArray);

  d1 = [NSKeyedArchiver archivedDataWithRootObject:theArray];
  result = [d1 writeToFile:@"archive.plist" atomically:YES];
  NSLog(@"Archived theArray with result: %d", result);

  NSLog(@"Attempting to resurect theArray");
  d2 = [[NSData dataWithContentsOfFile:@"archive.plist"] retain];
  if (d2) {
    NSLog(@"d2 has data");
  } else {
    NSLog(@"d2 is nil");
  }
  newArray = [[NSKeyedUnarchiver unarchiveObjectWithData:d2] retain];
  if (newArray) {
    printArray(newArray);
  } else {
    NSLog(@"I shouldn't be here!");
    NSLog(@"newArray is nil");
  }

  [pool release];
  return result;
}

------------------------------------
Thanks.

_______________________________________________
Help-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gnustep
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.