Re: Implementing delegate categories for subclasses
Christiaan Hofman <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sep 10, 2009, at 9:05, Christiaan Hofman wrote: > > On Sep 10, 2009, at 4:45, Kyle Sluder wrote: > >> On Wed, Sep 9, 2009 at 7:35 PM, David Dunham <[email protected]> wrote: >>> BTW, Apple still supports 10.4 with iTunes. (Which obviously isn't >>> Intel-64, >>> but it's apparently still a market too big for them to ignore.) >> >> So? That doesn't mean they need to compile the same code on 10.4 and >> 10.6. They can link against the 10.6 SDK with a deployment target of >> 10.4, which is the recommended way of doing cross-target development. >> >> --Kyle Sluder > > Again, at this point this is not an option for me, for various > reasons. > > Christiaan > Anyway, I found a solution that allows me to use any SDK and not to complicate complicate too much. It is based on a set of macros that are set (e.g. in the .pch) conditionally on the SDK: #if defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 #define OPTIONAL(name) @optional #define CONFORM(name) <name> #elif defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 #define OPTIONAL(name) @optional #define CONFORM(name) #else #define OPTIONAL(name) @end @interface NSObject (name) #define CONFORM(name) #endif I can then declare delegates as follows (if the superclass has a delegate I don't need the delegate ivar): @protocol FooDelegate <NSObject> // declare required delegate methods OPTIONAL(FooDelegate) // declare optional delegate methods @end @interface Foo : NSObject { // declare ivars id CONFORM(FooDelegate) delegate; } // declare methods - (id CONFORM(FooDelegate))delegate; - (void)setDelegate:(id CONFORM(FooDelegate))aDelegate; @end If I don't want to support the 10.4 SDK (or earlier) I can forget about the OPTIONAL macro and just directly use @optional. Christiaan