I want to know the syntax for passing arrays of pointer to a class method.
Myclass 开发者_开发问答*arr[TOTAL];
what is the syntax for the class method to take arr?
It is extremely atypical to pass a language array full of Objective-C objects or classes to a method.
I'd suggest:
+ (void) classMethod: (NSArray *) arrayOfClasses;
And:
[MyClass classMethod: [NSArray arrayWithObjects: [Foo class], [Bar class], nil]];
If the number of elements in the array is fixed, then
+ (void)someMethod:(MyClass *[])array;
is sufficient. Otherwise, pass the number of elements in the array:
+ (void)someMethod:(MyClass *[])array count:(NSUInteger)count;
In order to use the methods above,
MyClass *array[TOTAL];
array[0] = …;
array[1] = …;
…
array[TOTAL - 1] = …;
[MyClass someMethod:array];
or
[MyClass someMethod:array count:TOTAL];
A class method starts with a +
. Making it take an array as a parameter is done the same way as you would do it with any other pointer-taking method/function in C or Objective-C:
+ (void)myClassMethod:(MyClass **)arrayOfMyClassPointers;
It is a little strange to be using a C-style array to hold pointers to objects, though - what are you really trying to do?
精彩评论