• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: cString deprecated!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cString deprecated!


  • Subject: Re: cString deprecated!
  • From: Dustin Voss <email@hidden>
  • Date: Fri, 6 Sep 2002 06:01:40 -0700

On Thursday, September 5, 2002, at 05:04 AM, Rosyna wrote:

Ack, at 9/4/02, Dustin Voss said:

I'd actually use the following code:

id string;
CFStringRef cfstring;
cfstring = CFStringCreateWithCString (NULL, theCString, encoding);
string = [self initWithString:(NSString*)cfstring];

Why self? If you do have a method named initWithString in self, then it's named incorrectly. [NSString stringWithString:(NSString*)cfstring];

I'm sorry, I didn't include enough context. This code would be for an "initWithCString" method in an NSString category. The return value shouldn't be auto-released, so I don't call "stringWithString".

CFRelease (cfstring);

This is *very* bad. You *must* check for NULL cause CFRelease has this lame thing where it calls abort or something if you pass it NULL. Even though you can free a NULL.

Oh? I didn't know that. Thanks.

return string; // or [string autorelease] if this is a stringWith... method.

reverse that.


--
Dustin
_______________________________________________
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.

References: 
 >Re: cString deprecated! (From: Rosyna <email@hidden>)

  • Prev by Date: Re: Addressbook api
  • Next by Date: Re: undo text in an NSTextView
  • Previous by thread: Re: cString deprecated!
  • Next by thread: Re: cString deprecated!
  • Index(es):
    • Date
    • Thread