Skip navigation.
 
mlRe: Release understanding help?
FROM : Thomas Davie
DATE : Tue Dec 07 19:25:28 2004

I don't see why stringWithFormat is considered to be better than
stringByAppendingString...

[NSString stringWithFormat:@"0123456789mc/\" %@", [[NSUserDefaults
standardUserDefaults] objectForKey:NSDecimalSeparator];
and
[@"0123456789mc/\" " stringByAppendingString:[[NSUserDefaults
standardUserDefaults] objectForKey];
are pretty much as readable as each other.  In fact the second one
could be considered clearer because the reader doesn't have to scan
along the string to find the %@. They are equally efficient (they both
have to create and free two string objects).  Is there a reason to
chose one over the other... Other than that the second is more
readable.

Bob

--
God is real... Unless you define it as an integer.
On 7 Dec 2004, at 12:27, j o a r wrote:

>
> On 2004-12-07, at 12.55, Thomas Davie wrote:
>

>>> NSString * validChars = [[NSString alloc] initWithFormat :
>>> @"%@%@",@"0123456789mc/'\" ",[[NSUserDefaults standardUserDefaults]
>>> objectForKey:NSDecimalSeparator]];
>>> //and remove the following line :
>>> //validChars = [validChars stringByAppendingString:[[NSUserDefaults
>>> standardUserDefaults] objectForKey:NSDecimalSeparator]];

>>
>> The alternative and possibly slightly neater and more cocoaish
>> approach is to autorelease validChars so that it doesn't leak:
>>
>> NSString* validChars = [[[NSString alloc] initWithString:
>> @"0123456789mc/'\" "] autorelease];
>> validChars = [validChars stringByAppendingString:[[NSUserDefaults
>> standardUserDefaults] objectForKey:NSDecimalSeparator]];

>
> Even more cocoaish:
>
> NSString *validChars = [NSString stringWithFormat: @"0123456789mc/'\"
> %@", [[NSUserDefaults standardUserDefaults] objectForKey:
> NSDecimalSeparator]];
>
> You should probably add some sort of error checking on the value
> returned by NSUserDefaults before you add it to the string.
>
> j o a r
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/tom.<email_removed>
>
> This email sent to tom.<email_removed>

Related mailsAuthorDate
mlRelease understanding help? Mark Dawson Dec 7, 02:35
mlRe: Release understanding help? Byron Wright Dec 7, 03:17
mlRe: Release understanding help Š mark Dec 7, 03:32
mlRe: Release understanding help? Sherm Pendley Dec 7, 06:20
mlRe: Release understanding help? Thomas Davie Dec 7, 12:55
mlRe: Release understanding help? j o a r Dec 7, 13:27
mlRe: Release understanding help? Thomas Davie Dec 7, 19:25
mlRe: Release understanding help? j o a r Dec 7, 21:56
mlRe: Release understanding help? Thomas Davie Dec 7, 23:01