• 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: Roland King <email@hidden>
  • Date: Wed, 25 Sep 2013 06:58:14 +0800

Casting doesn't change what an object is, if your objects are As then they are As and all your cast is doing is lying about it so the compiler allows you to call a method without complaining, but the call will fail. If you want Bs you need to create Bs.

> On 24 Sep, 2013, at 11:38 pm, Koen van der Drift <email@hidden> wrote:
>
> In my app I am using a 3rd party framework, and I have subclassed (objB) one of the classes (objA) for additional functionality.
>
> At one point I am getting an NSCountedSet from the framework with objects objA.  When I enumerate these, I'd like to cast them as objB, to access the additional functionality (doSomethingNew).  But whatever I try, the objects are always casted as objA.
>
> NSCountedSet *cs = [framework countSymbols];
>
>        for (objB *obj in cs)
>        {
>            NSDictionary *ec = [objB doSomethingNew];  <<== throws error, because objA doesn't know about doSomethingNew
>
>    //    etc
>    }
>
>
> or:
>
> NSCountedSet *cs = [framework countSymbols];
>
>        for (id *obj in cs)
>        {
>            NSDictionary *ec = [((ObjB*) obj) doSomethingNew];  <<== throws error, because objA doesn't know about doSomethingNew
>
>    //    etc
>    }
>
>
> Is it possible what I am trying to do?
>
> - Koen.
> _______________________________________________
>
> 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


References: 
 >Casting objects in NSCountedSet (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: How to discover the volume id to use in a File Reference URL
  • Next by Date: Re: How is one supposed to use a UIPageViewController in a storyboard?
  • Previous by thread: Re: Casting objects in NSCountedSet
  • Next by thread: configuring Xcode to place products in different locations based on selected Architecture
  • Index(es):
    • Date
    • Thread