On Feb 24, 2011, at 1:18 AM, Lee Ann Rucker wrote: > You can't, but you can declare protocols for your ObjC++ classes in separate > headers then have the ObjC classes interact with "NSObject<Foo>" instead of > Foo objects directly. > > FooProtocol.h > > @protocol Foo > // methods the pure ObjC classes need to see > @end > > Foo.h > > #import "FooProtocol.h" > @interface Foo : NSObject <Foo> > ... > > Foo.mm > #import "Foo.h" > // do C++ things here > > Bar.m > > #import "FooProtocol.h" > // do things with NSObject<Foo> >
This would be an excellent approach, since protocols are the real and pure interfaces -- like "formal" duck-typing :) However, with protocols alone you cannot create objects - you need some sort of factory method, declared in some other class: id<Foo> myFooObject = [someObject newFoo]; Note: someObject can be a class object or an instance object. It just needs to implement the factory methods. The resulting object can be an instance of any class, it doesn't need to be class Foo. Regards Andreas_______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com