• 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: Casting to a superclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Casting to a superclass


  • Subject: Re: Casting to a superclass
  • From: Raphael Sebbe <email@hidden>
  • Date: Mon, 16 Jul 2001 17:08:04 +0200

On Monday, July 16, 2001, at 04:50 PM, Rob Rix wrote:

Hello, all.

I'm writing a utility class, which will have an NSMutableSet as an ivar. I want users of the class to be able to access the set, but as an immutable object.
So, can I typecast the NSMutableSet to NSSet, or should I just return [NSSet setWithSet:someSet];?


You can actually do both, but casting won't change the internal representation of the set and it will thus keep its mutability. If you really want to preserve it, use the later approach. Also note that users of your API shouldn't try to add objects to the returned set if it's said to be immutable. For this reason, I believe the former approach is widely accepted and used...

Raphael


References: 
 >Casting to a superclass (From: Rob Rix <email@hidden>)

  • Prev by Date: Casting to a superclass
  • Next by Date: Re: Casting to a superclass
  • Previous by thread: Casting to a superclass
  • Next by thread: Re: Casting to a superclass
  • Index(es):
    • Date
    • Thread