• 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
Best Practice for Returning Immutable Objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best Practice for Returning Immutable Objects?


  • Subject: Best Practice for Returning Immutable Objects?
  • From: Karl Moskowski <email@hidden>
  • Date: Tue, 3 Jun 2008 11:56:14 -0400

I have a few methods that return NSData objects, but the objects are created and manipulated as NSMutableData, and then copied to an immutable version along these lines:
NSMutableData *myData = [NSMutableData data];
:
:
return [NSData dataWithData:myData];


Would it be sufficient to cast, like this?
	:
	return (NSData *)myData;

Does this generalize to other non-collection classes, e.g., NSString?

TIA.

----
Karl Moskowski <email@hidden>
Voodoo Ergonomics Inc. <http://voodooergonomics.com/>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Best Practice for Returning Immutable Objects?
      • From: Bob Warwick - Codehackers <email@hidden>
    • Re: Best Practice for Returning Immutable Objects?
      • From: j o a r <email@hidden>
    • Re: Best Practice for Returning Immutable Objects?
      • From: Mike Abdullah <email@hidden>
    • Re: Best Practice for Returning Immutable Objects?
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Re: File still in use after closing document window
  • Next by Date: Re: CoreData file format stability
  • Previous by thread: Re: How to sort smoothly when NSTableColumn's Sort Key is empty
  • Next by thread: Re: Best Practice for Returning Immutable Objects?
  • Index(es):
    • Date
    • Thread