Reputation: 3063
I have converted an NSArray to NSString using below code Suppose i have an array with some data in it.
NSString *sample=[array description];
NSLog(@"%@",sample);
which prints:
(
{
URL = "1a516af1a1c6020260a876231955e576202bbe03.jpg##37911944cc1ea8fd132ee9421a7b3af326afcc19.jpg";
userId = 0;
wallpaperId = 31;
},
{
URL = "a9356863fa43bc3439487198283321622f88e31f.jpg##f09c743ebdc26bb9f98655310a0529b65a472428.jpg";
userId = 0;
wallpaperId = 30;
}
)
It looks like array but it is actually a string. Now I am wondering, how can I reconvert back to NSArray? Help appreciated.
And please this not a duplicate question, I couldn't found the same anywhere on SO.
Upvotes: 1
Views: 112
Reputation: 9
the
NSString componentsseparatedbystring
method will return an array of components separated by a string
Upvotes: -1
Reputation: 122458
You cannot rely on the results of description
as it is not a convert to string operator, but merely a debugging aid. There is nothing to stop it changing between O/S releases and there is no equivalent fromDescription
method.
The conventional way of serializing an Objective-C collection to and from a string is to use JSON, so look at the NSJSONSerialization
class.
Upvotes: 5