FROM : Andy Lee
DATE : Wed Jul 02 21:22:28 2008
On Jul 2, 2008, at 2:48 PM, James Montgomerie wrote:
> 2) Define a custom C struct (like NSRect, but with e.g. 'string' and
> 'offset' members) and return objects in it. Just like any other
> returned objects, the caller would be expected to retain them
> individually if it needed to keep them around.
Someone asked a similar question recently, with something like this
struct solution as one of the possible options. I rejected this
option, but upon reflection my reasons didn't quite make sense; I
don't think it's such a bad option now, though it makes me
uncomfortable for some reason.
Another option you didn't mention is to return *both* values in
pointers, and have the return type be void. This way you wouldn't be
implying one is more important than the other. A method like this
should have a name beginning with "get", as in getString:(NSString
**)stringPtr offset:(int *)offsetPtr. There is quite a bit of
precedent for methods of this form -- in the Xcode documentation
window, you can do an API "Starts With" search, sort by language, and
look at the Objective-C methods.
--Andy
DATE : Wed Jul 02 21:22:28 2008
On Jul 2, 2008, at 2:48 PM, James Montgomerie wrote:
> 2) Define a custom C struct (like NSRect, but with e.g. 'string' and
> 'offset' members) and return objects in it. Just like any other
> returned objects, the caller would be expected to retain them
> individually if it needed to keep them around.
Someone asked a similar question recently, with something like this
struct solution as one of the possible options. I rejected this
option, but upon reflection my reasons didn't quite make sense; I
don't think it's such a bad option now, though it makes me
uncomfortable for some reason.
Another option you didn't mention is to return *both* values in
pointers, and have the return type be void. This way you wouldn't be
implying one is more important than the other. A method like this
should have a name beginning with "get", as in getString:(NSString
**)stringPtr offset:(int *)offsetPtr. There is quite a bit of
precedent for methods of this form -- in the Xcode documentation
window, you can do an API "Starts With" search, sort by language, and
look at the Objective-C methods.
--Andy
| Related mails | Author | Date |
|---|---|---|
| James Montgomerie | Jul 2, 20:48 | |
| Abernathy, Joshua | Jul 2, 20:56 | |
| Stephen J. Butler | Jul 2, 20:58 | |
| Jean-Daniel Dupas | Jul 2, 21:14 | |
| Andy Lee | Jul 2, 21:22 | |
| Andy Lee | Jul 2, 21:30 | |
| Joel Norvell | Jul 2, 21:33 | |
| Bob Smith | Jul 2, 22:03 | |
| Keith Duncan | Jul 2, 22:19 | |
| David Casseres | Jul 4, 04:02 |






Cocoa mail archive

