Sign in to follow this  

Objective C NSMutableArray Equivalence

This topic is 2586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
Original post by ApochPiQ
Probably the closest equivalent would be std::vector. However, keep in mind that Objective C and C++ are very different languages, and the correspondence is far from 1:1.


Thanks... I shall take a deeper look at that.
Jack

Share this post


Link to post
Share on other sites
Hi rip-off,
Thanks for your reply. If there is no equivalent for this statement, could you, at your convenience, explain what this code does? because I am porting an objective c project to Visual C++ and I came across a lot of troubles.
Thanks a lot
Jack

Share this post


Link to post
Share on other sites
NSMutableArray can hold any object type so it's similar to std::vector<Base*> where all your objects inherit from Base. You can then use the typeid operator for roughly the same functionality as Objective C offers. There's also boost::any, but I think it operates on value types, which is fundamentally different to the way Objective c handles objects.

Share this post


Link to post
Share on other sites
Note that NSArray's and NSMutableArray's are often used with a single type only, so you most likely won't need a fancy solution for that in C++. If you have a NSMutableArray that only ever contains NSString*'s, a std::vector<std::string> (or std::wstring) is just fine.


Also, the two languages are significantly different that a 1:1 translation is not going to give the best results. One thing would be memory management - Objective C uses a retain count system, accompanied by autorelease pools. In C++, the most similar to that are probably shared pointers, but you can also take advantage of the stack and things like RAII. Another thing would be Objective C's messaging system. C++ does not have something like that built-in, so if your project depends on that, you may need to find an alternative solution in C++.

Share this post


Link to post
Share on other sites

This topic is 2586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this