Re: Using NSMutableString* for NSString* result
Re: Using NSMutableString* for NSString* result
- Subject: Re: Using NSMutableString* for NSString* result
- From: "Laurent Daudelin" <email@hidden>
- Date: Fri, 03 Oct 2003 12:04:39 -0400
If the purpose is to really return an NSString (an immutable string object),
then in your implementation of 'myMutableString', you should do something
like:
return [NSString stringWithString:myMutableString]
This will ensure that the object returned cannot be modified in your back.
And, btw, if this is your intent, returning an immutable version of your
string, you shouldn't call your method 'myMutableString' because it implies
that the string returned will be mutable, i.e. modifiable.
-Laurent.
--
===========================================================================
Laurent Daudelin Developer, Multifamily, ESO, Fannie Mae
mailto:email@hidden Washington, DC, USA
************************* Usual disclaimers apply *************************
>
From: "Matt Gough" <email@hidden>
>
Date: Fri, 03 Oct 2003 16:28:54 +0100
>
To: "cocoa dev" <email@hidden>
>
Subject: Using NSMutableString* for NSString* result
>
>
Dear all,
>
>
(I am just starting out in Cocoa)
>
>
I have a function that returns an NSString*. Internally I use an
>
NSMutableString to build up the result value.
>
>
Is it OK to just return (NSString*)myMutableString, or do I have to do copy
>
the string in to a 'proper' NSString? (It is assumed that the function has
>
no knowledge as to how its result will be used elsewhere)
_______________________________________________
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.