• 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 objects in NSCountedSet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Casting objects in NSCountedSet


  • Subject: Re: Casting objects in NSCountedSet
  • From: Kyle Sluder <email@hidden>
  • Date: Tue, 24 Sep 2013 09:37:30 -0700

On Sep 24, 2013, at 9:26 AM, Koen van der Drift <email@hidden> wrote:

>
> On Sep 24, 2013, at 11:52 AM, Kyle Sluder <email@hidden> wrote:
>
>> No, this doesn't make sense. Casting just tells the compiler "I know better than you and can guarantee you this expression is actually of this type". It doesn't "convert" objects from one type to another—how would it even do that?
>
> That's interesting, I've used casting before, eg:
>
> myClass *obj = (myClass*)[myArray objectAtIndex: index];
>
> and never ran into this.

That will work fine if the objects in the array are actually instances of myClass. In your case, the objects in the set are instances of the superclass, and no amount of casting will convert them to instances of the subclass.

>
>
> So besides hacking the framework, is there a way to accomplish this?

If your additional methods don't override any methods of the superclass, you could convert the subclass to a category. You can even add per-instance storage using associated objects.

--Kyle Sluder

_______________________________________________

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: Casting objects in NSCountedSet
      • From: Koen van der Drift <email@hidden>
References: 
 >Casting objects in NSCountedSet (From: Koen van der Drift <email@hidden>)
 >Re: Casting objects in NSCountedSet (From: Kyle Sluder <email@hidden>)
 >Re: Casting objects in NSCountedSet (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Casting objects in NSCountedSet
  • Next by Date: Re: Casting objects in NSCountedSet
  • Previous by thread: Re: Casting objects in NSCountedSet
  • Next by thread: Re: Casting objects in NSCountedSet
  • Index(es):
    • Date
    • Thread