Nilam Goswami Nilam Goswami - 5 months ago 8
Objective-C Question

split array values into string value?

my code is...

responseElement = [[bodyElement childrenNamed:@"GET_AllProductFrameShapeResponse"] objectAtIndex:0];
resultElement = [[responseElement childrenNamed:@"GET_AllProductFrameShapeResult"] objectAtIndex:0];

for (SMXMLElement *eventElements in [resultElement childrenNamed:@"Get_FrameShape"])
{
NSMutableDictionary *dicEventsData = [[NSMutableDictionary alloc] init];

[dicEventsData setValue:[eventElements valueWithPath:@"FrameShape"] forKey:@"FrameShape "];

[frameShapeResult addObject:dicEventsData];
}
NSLog(@"frameShape result %@", frameShapeResult);


and i get following array

frameShape result (
{
"FrameShape " = OVEL;
},
{
"FrameShape " = Wayfarer;
},
{
"FrameShape " = "Club Master";
},
{
"FrameShape " = Aviator;
},
{
"FrameShape " = Wayferer;
},
{
"FrameShape " = Rectangle;
},
{
"FrameShape " = Round;
},
{
"FrameShape " = Oval;
},
{
"FrameShape " = "Cat-Eye";
},
{
"FrameShape " = "Cat Eye";
},
{
"FrameShape " = ClubRound;
},
{
"FrameShape " = Square;
}
)


i want following into array from array

OVEL
Wayfarer
Club Master"
Aviator
Wayferer
Rectangle
Round
Oval
Cat-Eye
Cat Eye
ClubRound
Square

Answer

Try this:

Space added in key

NSArray * FrameShape = frameShaperesult; // array of you result which contains dictionary objects. 
FrameShape = [FrameShape valueForKey:@"FrameShape "]; // array that contains string objects which you mentioned in question

This final FrameShape array will contains only string as object and you can access each by for loop.

If you want all objects in one string try this:

NSString *str = [FrameShape componentsJoinedByString:@","]; // all object will join by ,(comma) you can change it as per your need.