Is it possible to pass an array as an argument for a function?
-
5Sure, it's an overly simple question, but -5 in 7 minutes? What on earth? I've seen far worse (and more argumentative) questions last weeks and not hit that.Steven Fisher– Steven Fisher2011-07-08 18:09:11 +00:00Commented Jul 8, 2011 at 18:09
-
1@Steven I can see how it can come across as harsh, but one of the principle tenets of a good question is that you've done some research beforehand. This is the type of question that could very easily have been answered by spending a little time on Google or on some tutorials instead of knee-jerking on to SO.Doug Stephen– Doug Stephen2011-07-08 18:28:06 +00:00Commented Jul 8, 2011 at 18:28
-
2Sure, but simple is supposed to be welcome here. Even if something's easily answered via a Google search, if the answer can be better it belongs here. This is now the second hit for this google query, and the first not directly tied to classic C arrays. See here: stackoverflow.com/questions/1003841/…Steven Fisher– Steven Fisher2011-07-08 21:21:18 +00:00Commented Jul 8, 2011 at 21:21
-
@Steven: simple is allowed, thus the question is not closed. Lazy is not encouraged, thus it is downvoted. That question you linked to is among the most controversial in the history of SO. The other founder of SO actually disagrees with its being posted.jscs– jscs2011-07-08 22:16:46 +00:00Commented Jul 8, 2011 at 22:16
Add a comment
|
1 Answer
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];
3 Comments
jscs
Those aren't functions; they're methods.
Yann Ramin
@Josh: Correct! At some point, the discussions stops being about Objective-C and rather about C, therefore I used methods as an example to stay within Objective-C.
jscs
But you made methods whose (pseudo-)names say that they're functions. Seems likely to cause confusion.