objective c - How to get string from NSArray which contains bracket -
my code this: (here name nsarray , object array passed function parameter)
[name addobject:object]; nslog(@"%@",name); when got output this:
{name:\"malay basu"\ date:\"2013-04-18"\ senderid:\"24" receiverid:\"25"} now when retrieving name field of array string got string as:
nsstring *temp = [name valueforkey:@"name"]; output: `( malay basu )` now when string operations string appending or comparison of string got error like:
terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarrayi isequaltostring:]: unrecognized selector sent instance 0x16635ed0' to remove error need string without bracket displays above. need malay basu instead of ( malay basu ).so next step fetch proper string string variable because need operations string compare,string appending. appreciated.
check purpose of methods using.
-valueforkey: when called on nsarray
returns array containing results of invoking valueforkey: using key on each of array's objects.
so object isn't string, it's array of strings. log statement shows brackets because log notation nsarray. {} brackets log notation nsdictionary.
to process result strings, use loop.
for (nsstring *astring in anarray) { nslog(@"%@ %@", astring, nsstringfromclass([astring class]); }
Comments
Post a Comment