Re: getCString a good idea here?
Re: getCString a good idea here?
- Subject: Re: getCString a good idea here?
- From: Prachi Gauriar <email@hidden>
- Date: Sun, 13 Jul 2003 13:48:11 -0500
On Sunday, July 13, 2003, at 3:32 AM, Neil Earnshaw wrote:
Basically, this means that getCString isn't a method for
NSConstantString. So your problem isn't that you're using getCString
improperly, it's that getCString doesn't exist. There is a method
called getCString: (notice the ':'), but that, like all Cocoa methods
that start with get... means that the method returns a value by
reference
The documentation says that -(void)getCString:(char*)buffer _takes_ a
reference and puts a _copy_ of the chars in the area pointed to,
rather than returning a reference. Is this the usual convention for
get<Something> accessors? (I'm a bit of a newbie myself and I've
never come across it in any of the books.)
According to the section on accessor methods in the coding guidelines
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc/uid/
20001282/BCIGGFCC>, get<something> is used when you're returning
something indirectly. I believe Ali Ozer said the same thing in one of
his talks two years ago at WWDC. I think remember reading it in the
Anguish-Buck-Yacktman book, but I'm not sure.
Using Xcode's documentation search (which rocks Xcode team!), the only
exceptions to this rule that I could find were NSMethodSignature's
getArgumentTypeAtIndex: and NSRunLoop's getCFRunLoop, each which return
their values directly.
(which is not what you want), like
char *myCString;
[myString getCString:&myCString];
Wouldn't the '&' mean you are supplying the address of a pointer to a
char, i.e. a char**?
Indeed. My mistake. That's what I get for not looking at the
documentation. I thought it was char**. It seems that with any other
type of object, you pass the address to the pointer, but char *'s
aren't like that (and that makes sense). And yes, you do need to
allocate space. Sorry 'bout that.
-Prachi
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.