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];
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With