Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional exclusion of code in Swift

Tags:

swift

ifndef

I am trying to exclude some parts of a Swift file for a specific target. Yet I did not find any replacement of the #ifndef objective-c directive and moreover if I use a form of the kind:

#if taxi_coops
func pippo(){
    println("pippo");
}
#else
func triggerActiveLocationUpdate(entering:Bool){}
#endif

The preprocessor totally ignores the directive and tries to compile triggerActiveLocationUpdate. Please note the #if taxi_coops directive is respected in other parts of the same file.

Is there some way to simply exclude some pieces of code in Swift and/or why my fix does not work?

like image 660
Fabrizio Bartolomucci Avatar asked Jul 14 '15 14:07

Fabrizio Bartolomucci


1 Answers

The issue was about replicating the configuration in the Other Swift Flags file in the form

-D option

Apparently Swift ignores the flags in the preprocessor field. Now it accepts ||, && and ! without any problem with syntax:

#if option || !option2
......
#elseif option3
......
#endif
like image 106
Fabrizio Bartolomucci Avatar answered Sep 29 '22 15:09

Fabrizio Bartolomucci