3

I did test this code, but it cause SIGABRT error.

NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data]

NSData is plist data with xml format. This code works fine.

[urlData writeToFile:[self docPath] atomically:YES];
array = [[NSMutableArray alloc] initWithContentsOfFile:[self docPath]];

How can I change NSData to NSArray without file conversion?

ChangUZ
  • 5,380
  • 10
  • 46
  • 64

1 Answers1

7

This assumes you have populated NSString *filepath with the filepath of your saved data file.

NSPropertyListFormat format;
NSData *dataFromFile = [NSData dataWithContentsOfFile:fileNameWithPath];
NSArray *arrayFromFile = nil;
if (dataFromFile) {
    arrayFromFile = [NSPropertyListSerialization propertyListFromData:dataFromFile
                                                       mutabilityOption:NSPropertyListMutableContainers
                                                                 format:&format 
                                                       errorDescription:NULL];
}

Hope that helps...

Mark Armstrong
  • 819
  • 6
  • 9