Re: Casting objects in NSCountedSet

2013-09-24 Thread Roland King
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

Re: Casting objects in NSCountedSet

2013-09-24 Thread Koen van der Drift
On Sep 24, 2013, at 12:37 PM, Kyle Sluder wrote: > 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. Good call for the category, that should be easy to impl

Re: Casting objects in NSCountedSet

2013-09-24 Thread Paul Scott
On Sep 24, 2013, at 9:29 AM, Paul Scott wrote: >> No, you should be able to cast, as the method is found dynamically at >> run-time. Simple test program shows this. > > Your app does not demonstrate Koen's situation, in which he receives a set of > ObjectA instances from the framework. You ar

Re: Casting objects in NSCountedSet

2013-09-24 Thread Kyle Sluder
On Sep 24, 2013, at 9:29 AM, Paul Scott wrote: > No, you should be able to cast, as the method is found dynamically at > run-time. Simple test program shows this. Your app does not demonstrate Koen's situation, in which he receives a set of ObjectA instances from the framework. --Kyle Sluder

Re: Casting objects in NSCountedSet

2013-09-24 Thread Kyle Sluder
On Sep 24, 2013, at 9:26 AM, Koen van der Drift wrote: > > On Sep 24, 2013, at 11:52 AM, Kyle Sluder 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" o

Re: Casting objects in NSCountedSet

2013-09-24 Thread Paul Scott
No, you should be able to cast, as the method is found dynamically at run-time. Simple test program shows this. I created a new project and edited the AppDelegate.h as here: #import @interface SYNAppDelegate : NSObject @property (assign) IBOutlet NSWindow *window; @end @interface ObjectA :

Re: Casting objects in NSCountedSet

2013-09-24 Thread Koen van der Drift
On Sep 24, 2013, at 11:52 AM, Kyle Sluder 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

Re: Casting objects in NSCountedSet

2013-09-24 Thread Kyle Sluder
On Sep 24, 2013, at 8:38 AM, Koen van der Drift 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

Casting objects in NSCountedSet

2013-09-24 Thread Koen van der Drift
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 func