Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-processor macros in xcconfig files

is is possible to use macros in config files? I want to achieve something like:

if iPad
set variable to 1
else
set variable to 0

Is that possible? I would rather not use scripts for this.

like image 277
John Lane Avatar asked Sep 30 '12 17:09

John Lane


2 Answers

You generally should check this at runtime rather than compile time. See iOS - conditional compilation (xcode).

If you don't do it that way, I typically recommend using different targets as hinted at by @Robert Vojta.

That said, I can imagine cases where this would be useful in some piece of shared code. So...

There is an xcconfig variable you can use called TARGETED_DEVICE_FAMILY. It returns 1 for iPhone and iPod Touch, and 2 for iPad. This can be used to create a kind of macro. I don't highly recommend this approach, but here's how you do it. Let's say you were trying to set some value called SETTINGS:

// Family 1 is iPhone/iPod Touch. Family 2 is iPad
SettingsForFamily1 = ...
SettingsForFamily2 = ...
SETTINGS = $(SettingsForFamily$(TARGETED_DEVICE_FAMILY))

I've done this a few times in my projects (for other problems, not for iPad detection). Every time I've done it, a little more thought has allowed me to remove it and do it a simpler way (usually finding another way to structure my project to remove the need). But this is a technique for creating conditionals in xcconfig.

like image 151
Rob Napier Avatar answered Nov 10 '22 02:11

Rob Napier


AFAIK it's not possible. But if you want to solve simple task - lot of common settings and just few variables have different values, you can do this:

generic.xcconfig:

settings for both configs

ipad.xcconfig:

#include "generic.xcconfig"
ipad-specific-settings

iphone.xcconfig

#include "generic.xcconfig"
iphone-specific-settings

This can solve your condition need. I do use this schema frequently.

like image 22
zrzka Avatar answered Nov 10 '22 01:11

zrzka