Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c syntax for passing a c-style array of NSStrings

What's the best syntax for passing a c-style array containing NSString* to an objective-c method? Here's what I'm currently using:

- (void) f:(NSString **) a {

}

- (void) g {
    NSString* a[2] = {@"something", @"else"};
    [self f:a];
}
like image 855
SundayMonday Avatar asked Jan 17 '23 17:01

SundayMonday


1 Answers

Your only other option is the following:

- (void) f:(NSString* []) a {

}

It's identical when compiled. I don't know about "best", but I prefer this version's readability. It's easier to infer that the pointer you're passing is intended to be used as an array. Pointers to pointers have different uses elsewhere (see the various NSError** parameters used in the iOS SDK), so the distinction is helpful.

like image 145
Matt Wilding Avatar answered Jan 31 '23 08:01

Matt Wilding