0

I just wanted a few thoughts on the best general approach that I could take in this situation. So, I'm working on a project that currently has a few different targets but in the future is potentially going to have more targets with significantly more differences across targets than we have right now. (Currently, out targets different in url's that requests are made out to, a few assets and some other basic UI differences). Now my question is, moving forward, what would be the best way to manage different targets- obviously one approach is to use preprocessor macros and have a bunch of #ifdefs but I was wondering if there are better approaches that people can suggest. In terms of the differences that I know for sure will be coming, we're definitely going to have to render different views based on the target we're running and also our actual request might also change (maybe our post request might have different parameters based on target etc.)

So outside of using target based conditional execution, what are some other approaches I could use here outside of just building separate applications since there's considerable similarity across the board?

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
David West
  • 552
  • 2
  • 9
  • 21
  • My starting point is that I hate dealing with preprocessor-based logic. From there, my tendency would be to create one or more frameworks that capture the functionality that doesn't change by target (or that can be parameterized by the caller). I would then look at creating individual projects that share those frameworks. Notably different behaviour can be handled by polymorphism in subclasses. – Phillip Mills Aug 09 '17 at 18:43
  • It really depends on your differences and your differents projects. Like @PhillipMills I tend to dislike macros. In one of my project, I created a singleton where there I used macro to differentiate the targets, but then put some values to its property to be able to read them on running and allow or disable some features. – Larme Aug 09 '17 at 21:25
  • @Larme Can you show me an example of how you did this ie used a singleton to differentiate between targets? – David West Aug 10 '17 at 15:05
  • Main idea of use `if([[MyParam sharedInstance] isFeatureAllowed]){//Do some stuff}`. In the init of the singleton: `#ifdef MyTargetIsTarget1 _isFeatureAllowed = FALSE; #endif #ifdef MyTargetIsTarget2 _isOtherFeatureAllowed = YES; #endif` (I didn't do an if/else to explicit, in case you set by default YES/NO to some properties). You can put the macro in each target of the project `Build Settings`. – Larme Aug 10 '17 at 15:08

0 Answers0