0
(void) connection:(NSURLConnection )connection didReceiveData:(NSData )data
{
[self.receivedData appendData:data];

// convert data to array 
// ??? the below is not working
NSMutableArray *receivedDataAsArray = [NSPropertyListSerialization         
propertyListFromData:self.receivedData      
mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];
}

I use the above with NSURLConnection to get the data (serialized array). I want to convert it to an NSMutableArray. While the above doesn't return an error, it doesn't return a populated array either (though I am definitely receiving data). Any help as to how to properly convert NSData/NSMutableData to NSArray/NSMutableArray?

  • possible duplicate of [Need to convert NSData to NSArray](http://stackoverflow.com/questions/2255430/need-to-convert-nsdata-to-nsarray) – Lukas Knuth Mar 15 '13 at 12:10

1 Answers1

1

Use NSKeyedArchiver for archiving object to data.

NSKeyedUnarchiver for unarchiving object from data:

NSArray *object = [NSKeyedUnarchiver unarchiveObjectWithFile:self.receivedData];
ILYA2606
  • 587
  • 3
  • 7