Pre-processor macros in xcconfig files
Asked Answered
S

3

6

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.

Spireme answered 30/9, 2012 at 17:22 Comment(1)
L
10

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.

Longwood answered 30/9, 2012 at 22:24 Comment(1)
That's a great tip! Thanks, but what do you do if the TARGETED_DEVICE_FAMILY flag is universal, i.e. returns 1,2?Spireme
A
5

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.

Argumentation answered 30/9, 2012 at 17:49 Comment(0)
C
0

That's not possible. Configuration files are not preprocessed (and compiled).

Chaplin answered 30/9, 2012 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.