Re: Casting objects in NSCountedSet
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