3

I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to convert this to an NSArray. Can anyone help me?

I am refactoring a method that currently does a synchronous request to the URL, using arrayWithContentsOfURL: to get the NSArray.

Thanks!!

Jacko
  • 12,665
  • 18
  • 75
  • 126

2 Answers2

9

Use +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] to convert the data, then check if the result -isKindOfClass:[NSArray class].

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

Use NSKeyedArchiver for archiving object to data.

NSKeyedUnarchiver for unarchiving object from data:

NSArray *object = [NSKeyedUnarchiver unarchiveObjectWithFile:self.receivedData];
ILYA2606
  • 587
  • 3
  • 7
  • 3
    Please don't re-post your answers word-by-word, but if you find another question provides an answer to this question, too, mark it as a duplicate of that question. – Lukas Knuth Mar 15 '13 at 11:56