• 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: NSString initWithFormat and stringWith
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString initWithFormat and stringWith


  • Subject: Re: NSString initWithFormat and stringWith
  • From: Michael Ash <email@hidden>
  • Date: Wed, 27 May 2009 11:48:08 -0400

On Wed, May 27, 2009 at 11:05 AM, Erik Buck <email@hidden> wrote:
> As an alternative, use
> NSString *string1 = [[NSString stringWithString:@"myFirstString"] retain];
> or NSString *string2 = [[NSString alloc] initWithString:@"mySecondString"];
> or NSString *string3 = [@"myThirdString" copy];

However you should never use any of these either.

You already have a string. If you need a string, then you have it, so use it.

This code can be *occasionally* useful if you need an independent copy
of a potentially mutable string. But of course @"" constructs are
never mutable.

This may seem nitpicky but I see a lot of newbies writing code just
like this. Their code is filled with stringWithString: calls for
absolutely no purpose, so I want to discourage that sort of thing.

Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: NSString initWithFormat and stringWith (From: Erik Buck <email@hidden>)

  • Prev by Date: UITableView data source/delegate flow of control
  • Next by Date: Re: NSString initWithFormat and stringWith
  • Previous by thread: Re: NSString initWithFormat and stringWith
  • Next by thread: Re: NSString initWithFormat and stringWith
  • Index(es):
    • Date
    • Thread