• 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: Using NSMutableString* for NSString* result
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
References: 
 >Using NSMutableString* for NSString* result (From: Matt Gough <email@hidden>)
 >Re: Using NSMutableString* for NSString* result (From: Nicholas Riley <email@hidden>)

  • Prev by Date: Re: Using NSMutableString* for NSString* result
  • Next by Date: Re: Using NSMutableString* for NSString* result
  • Previous by thread: Re: Using NSMutableString* for NSString* result
  • Next by thread: Re: Using NSMutableString* for NSString* result
  • Index(es):
    • Date
    • Thread