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 ?
Asked
Active
Viewed 90 times
0

rmaddy
- 314,917
- 42
- 532
- 579

David Safrastyan
- 725
- 7
- 18
-
maybe this will help you http://stackoverflow.com/questions/1150650/is-it-ok-to-use-classic-malloc-free-in-objective-c-iphone-apps – Alexander Dalshov Jul 09 '15 at 17:23
1 Answers
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