Rams
Rams

Reputation: 1751

convert all NSDate objects into array to NSString objects

i have an xml file having list of .Every date has a list of events.i want to display the date in uisegmentation control.when the user click the date in uisegmentation i am displaying the list of event for the date shown below.My xml structure is

<event>
</title>
</desc>
<date>01/02/2012</date>
</event>

I done everything the problem is.I am getting all dates and remove duplicates

[ datearray valueForKeyPath:@"@distinctUnionOfObjects.date"]

and i sort the date using

sortedArrayUsingSelector:@selector(compare:)

Now my array has a list of nsdate object .I want to convert nsdate object to nsstring..

I tried for loop and nsdateformatter to check every index and change into string and add into new array..it's a lengthy process...is it correct or any other better option

Finally

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:datearray]

Upvotes: 0

Views: 232

Answers (1)

MadhavanRP
MadhavanRP

Reputation: 2830

If I've understood your question right, you want to convert all the NSDate objects in your mutable array to NSString objects.

NSArray *arrayOfStrings=[dateArray valueForKey:@"description"];

valueForKey: will be called on all objects of date array and the results will be stored in the new array.

Upvotes: 1

Related Questions