I want to ask about the NSArray in objective C.
I want to create a dynamic array as I don’t know about the size of the array. And I also want to insert some of the data to the array. However, I don’t know how to decl, init and insert the element in to the array.
The following is the C++ version.
I want to create a empty array A and put all the array element in array B to A.
// empty array
string arrA[] = new string();
// put the arrB into arrA
for(int i=0; i < arrB.length(); i++)
arrA[i] = arrB[i];
Thank you very much.
You should use the class named
NSArrayorNSMutableArray. These are similar tostd::vectorhowever they are somewhat different in their use due to the way Objective-C works.The difference with Objective-C
NSArrayobjects is that they can take any type of object as long as it is a subclass ofNSObject.To access values you must use the
objectAtIndex:message.