How to insert items into NSArray object in C# (Monotouch)? I don’t find appropriate method to do so? In Objective-C side, there is a constructor called “initWithObjects” but I don’t find this on C# side.
pom
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sorry to answer your question with a question, but are you sure you want to create an NSArray?
I ask because MonoTouch does some work behind the scenes so that you don’t have to deal with NSArray.
If you go to the MonoTouch API Design page and do an in-page search for “NSArray”, you’ll find this:
In other words, unless you have a specific reason to, you don’t have to mess with NSArray.
But, if you do have a reason, or if it’s your preference, then Jason’s answer is correct:
The only thing I’d add is that, if you’re an Objective-C dev and giving MonoTouch a try, you’re used to this:
The difference is the “nil” at the end of the Objective-C version. MonoTouch’s NSArray doesn’t have this same requirement. You just pass it the objects you want it to contain, and it happily does so. No terminating null required 🙂
Hope this helps…