Re: NSString initWithFormat and stringWith
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