user559142
user559142

Reputation: 12527

Objective - C -> Pass Array As Function Argument

Is it possible to pass an array as an argument for a function?

Upvotes: 6

Views: 16233

Answers (1)

Yann Ramin
Yann Ramin

Reputation: 33197

Yes, of course.

C-array:

- (void)myFunction:(int*)array;
 ...

int bar[12];
[obj myFunction:bar];

NSArray:

- (void)myFunctionWithNSArray:(NSArray*)array;
...
NSArray *array = [[NSArray alloc] initWithObjects...];
[obj myFunctionWithNSArray:array];

Upvotes: 20

Related Questions