-2

If I have an array with the following:

NSArray *array = [NSArray arrayWithObjects:@"dog", "brown", "kid"];

And I loop over that

for (NSString *strings in [array reverseObjectEnumerator] { }

How do I join that those individual words in one final string?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
qweqweqwe
  • 343
  • 5
  • 8
  • 18

2 Answers2

1
NSArray* reversedArray = [[array reverseObjectEnumerator] allObjects];
[reversedArray componentsJoinedByString:" "]

See more at link: How can I reverse a NSArray in Objective-C?

Community
  • 1
  • 1
hahv
  • 582
  • 1
  • 4
  • 16
0

Don't loop over them. Just use:

[array componentsJoinedByString:" "]

... assuming you want a space between each word.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • Have to loop over them because I am reversing them first. – qweqweqwe Mar 11 '15 at 03:09
  • Certainly the functional way would be to loop over the one array, reversing words and depositing them in a second array, then join the second array to make the output string. – Tommy Mar 11 '15 at 03:16
  • trying to do that now. Cannot figure out how to make the output string. – qweqweqwe Mar 11 '15 at 03:17