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 <Cocoa/Cocoa.h> @interface SYNAppDelegate : NSObject <NSApplicationDelegate> @property (assign) IBOutlet NSWindow *window; @end @interface ObjectA : NSObject { } - (NSInteger)doSomethingNew; @end @interface ObjectB : ObjectA - (NSInteger)doSomethingOld; @end And edited the AppDelegate.m as here: #import "SYNAppDelegate.h" @implementation SYNAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { id obj = [[ObjectB alloc] init]; NSInteger i = [((ObjectB*) obj) doSomethingNew]; } @end @implementation ObjectA - (NSInteger) doSomethingNew { return 1; } @end @implementation ObjectB @end Setting a breakpoint on the shows that variable i is set to 1 as expected, with no runtime failure. Paul On Sep 24, 2013, at 8:52 AM, Kyle Sluder <k...@ksluder.com> wrote: > On Sep 24, 2013, at 8:38 AM, Koen van der Drift <koenvanderdr...@gmail.com> > 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? > > 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? > > --Kyle Sluder > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/pscott%40skycoast.us > > This email sent to psc...@skycoast.us -- Paul Scott psc...@skycoast.us
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com