Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is its ok to have multiple implementations per target in XCode?

I have a header file that defines a class interface:

// MyClass.h - included in all targets
//
@interface MyClass
+ (void) doThing;
@end

And I have two different implementation files - one per target.

// MyClass+targetA.m - Only included in targetA
//
@implementation MyClass
+ (void) doThing { NSLog(@"targetA"); }
@end


// MyClass+targetB.m - Only included in targetB
//
@implementation MyClass
+ (void) doThing { NSLog(@"targetB"); }
@end
  • Are there any issues with this approach?
  • Is there a better or simpler way to customise behaviour of each target?

The method MyClass will be for themeing the appearance of an app. There will be several methods on MyClass and several targets

like image 323
Robert Avatar asked Nov 01 '22 15:11

Robert


2 Answers

Yes that will work fine, and I have taken a similar approach, except that I have used conditional compilation, with one target exposing private functionality and another target exposing public functionality, but all targets sharing the same set of source files.

However the results of both our approaches are the same.

like image 169
trojanfoe Avatar answered Nov 08 '22 05:11

trojanfoe


So I'm actually prefer to setup OTHER_CFLAGS in target settings with my custom flag like TARGET_FREE for one of them. And then in the source I can write something like:

@implementation MyClass
+ (void) doThing {

#ifdef TARGET_FREE 
    // Code for one target
#else
    // Code for another
#endif

}
@end
like image 22
Skie Avatar answered Nov 08 '22 05:11

Skie