• 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: Returning exactly what has been promised
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning exactly what has been promised


  • Subject: Re: Returning exactly what has been promised
  • From: Damien Cooke <email@hidden>
  • Date: Wed, 23 Jul 2008 15:08:58 +0930

You could return like this

return [myWorkingMutableString copy];

This makes a immutable copy returning an NSString.

Regards
Damien

On 23/07/2008, at 2:24 PM, Steve Cronin wrote:

Folks;

I find if I have a method which returns an NSString for example, that often, in the interior of that method I will use an NSMutableString to construct the string I intend to return. My question concerns the actual final return statement.

Is there ANY reason to choose A over B?

A) return [NSString stringWithString:myWorkingMutableString];

B) return myWorkingMutableString;

It just kinda sticks in my craw me that I 'promised' an NSString and using (B) I don't return one.
Yeah I do understand inheritance and that a mutable entity isKindOfClass of the base class
I looking for reasons like edge cases, compiler optimization, error trapping, portability, etc..
Is there ANY benefit to the costs associated with the explicit declaration of (A)?


Thanks for helping me better understand!
Steve
_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Returning exactly what has been promised
      • From: Graham Cox <email@hidden>
References: 
 >Returning exactly what has been promised (From: Steve Cronin <email@hidden>)

  • Prev by Date: Returning exactly what has been promised
  • Next by Date: Re: Returning exactly what has been promised
  • Previous by thread: Returning exactly what has been promised
  • Next by thread: Re: Returning exactly what has been promised
  • Index(es):
    • Date
    • Thread