Re: Using NSMutableString* for NSString* result
Re: Using NSMutableString* for NSString* result
- Subject: Re: Using NSMutableString* for NSString* result
- From: Glenn Andreas <email@hidden>
- Date: Fri, 3 Oct 2003 12:06:45 -0500
On Fri, Oct 03, 2003 at 04:28:54PM +0100, Matt Gough wrote:
> Example 1:
-(NSString*) getSomeFancyString
{
NSMutableString* s = [NSMutableString new];
You don't want to use 'new'; use 'alloc', 'init'. Please (re)read
Apple's Objective-C book.
How about:
NSMutableString *s = [NSMutableString string];
> [s appendString:getSomeOtherString()];
... Other stuff to add/change the string
You should use either:
NSMutableString *s = [[NSMutableString alloc] initWithString:
getSomeOtherString()];
or:
NSMutableString *s = [getSomeOtherString() mutableCopy];
or
NSMutableString *s = [NSMutableString stringWithString:
getSomeOtherString()];
(you can use the class convience constructor methods with subclasses,
so you can also do things like "[NSMutableArray array]" instead of
"[[NSMutableArray alloc] init]" or "[NSMutableArray
arrayWithCapacity: 0]")
--
Glenn Andreas email@hidden
Theldrow, Blobbo, Cythera, oh my!
Be good, and you will be lonesome
_______________________________________________
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.