0

I have a function which transforms a std::vector into NSMutableArray. I have handled all the bridging actions, but there is one thing which I am not able to do. I want to make an NSMutableArray in that function, then copy the vector elements in that array, and then return pointer to it's beginning. In C++ I would simply allocate some necessary memory, use it and return the pointer to it's beginning, how to do the same for Objective-C ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
David Safrastyan
  • 725
  • 7
  • 18

1 Answers1

1

Once you've created the NSMutableArray, you just return it. The thing you're returning is a pointer. You "allocated some necessary memory" when you called [NSMutableArray alloc] (either directly or indirectly).

Remember that NSArray is not guaranteed to by contiguous memory, so "a pointer to its beginning" isn't really meaningful. You want a pointer to the object, and that's exactly what you have. Just return it.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610