<div dir="ltr"><div>It'd be nice if there was a predefined macro to let you know if you're inside of the header generation machinery. Last time I grazed the compiler it didn't set up any custom symbols in the preprocessor it uses for the first stage of processing the generated header. (rdar://27195567 - would like a preprocessor symbol when building a generated interface)</div><div><br></div><div>If you want to get gross, the bridging header is just another header and you can put your own defines in there - then look for it in your Food Header: (not actually tested, Xcode8b2 is throwing a fit before I even tried adding the #define. (rdar://27195434 - Some header files hang when generating interface)</div><div><br></div><div>Project-Bridging-Header.h</div><div><br></div><div>...</div><div>#define SUPPRESS_OLD_FOOD 1</div><div>#import "Foodies.h"</div><div><br></div><div><br></div><div>Foodies.h</div><div><br></div><div><span style="font-size:13px">typedef NS_OPTIONS(NSInteger, FoodType)</span><br style="font-size:13px"><span style="font-size:13px">{</span><br style="font-size:13px"><span style="font-size:13px"> FoodDairy = 1 << 0,</span><br style="font-size:13px"><span style="font-size:13px"> FoodMeat = 1 << 1,</span><br style="font-size:13px"><span style="font-size:13px"> FoodMushroom = 1 << 2,</span><br style="font-size:13px"><br>#if !SUPPRESS_OLD_FOOD<br style="font-size:13px"><span style="font-size:13px">// Old names</span><br style="font-size:13px"><span style="font-size:13px">dairyFood = FoodDairy,</span><br style="font-size:13px"><span style="font-size:13px">meatFood = FoodMeat,</span><br style="font-size:13px"><span style="font-size:13px">mushroomFood = FoodMushroom</span></div><div>#endif</div><div><span style="font-size:13px">};</span><br style="font-size:13px"></div><div><br></div><div>This has the unfortunate side effect (beyond making your bridging header complicated) that Xcode's generated header preview won't take your macro into account when previewing the generated interface. (rdar://27195567 - would like a preprocessor symbol, again)</div><div><br></div><div>Cheers,</div><div>++md</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 6, 2016 at 6:03 AM, Matteo via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Suppose I have an existing enum in Obj-C such as:<br>
<br>
typedef NS_OPTIONS(NSInteger, FoodType)<br>
{<br>
dairyFood = 1 << 0,<br>
meatFood = 1 << 1,<br>
mushroomFood = 1 << 2<br>
};<br>
<br>
I want to rename all the values so that swift code can use the shorter names. i.e<br>
<br>
typedef NS_OPTIONS(NSInteger, FoodType)<br>
{<br>
FoodDairy = 1 << 0,<br>
FoodMeat = 1 << 1,<br>
FoodMushroom = 1 << 2<br>
};<br>
<br>
generates:<br>
<br>
public struct FoodType : OptionSetType {<br>
public init(rawValue: Int)<br>
<br>
public static var Dairy: FoodType { get }<br>
public static var Meat: FoodType { get }<br>
public static var Mushroom: FoodType { get }<br>
}<br>
<br>
<br>
But I still want the old names so as not to have to update all of the existing Obj-C code and mess up my SVN history.<br>
<br>
At first I thought this would suffice:<br>
<br>
typedef NS_OPTIONS(NSInteger, FoodType)<br>
{<br>
FoodDairy = 1 << 0,<br>
FoodMeat = 1 << 1,<br>
FoodMushroom = 1 << 2,<br>
<br>
// Old names<br>
dairyFood = FoodDairy,<br>
meatFood = FoodMeat,<br>
mushroomFood = FoodMushroom<br>
};<br>
<br>
but that prevents the generated interface using the shortened names since all the values don’t follow the same pattern:<br>
<br>
public struct FoodType : OptionSetType {<br>
public init(rawValue: Int)<br>
<br>
public static var FoodDairy: FoodType { get }<br>
public static var FoodMeat: FoodType { get }<br>
public static var FoodMushroom: FoodType { get }<br>
<br>
public static var dairyFood: FoodType { get }<br>
public static var meatFood: FoodType { get }<br>
public static var mushroomFood: FoodType { get }<br>
}<br>
<br>
I was looking for something similar to NS_SWIFT_UNAVAILABLE such that I could do:<br>
<br>
typedef NS_OPTIONS(NSInteger, FoodType)<br>
{<br>
FoodDairy = 1 << 0,<br>
FoodMeat = 1 << 1,<br>
FoodMushroom = 1 << 2,<br>
<br>
// Old names<br>
dairyFood = FoodDairy NS_SWIFT_UNAVAILABLE,<br>
meatFood = FoodMeat NS_SWIFT_UNAVALIBLE,<br>
mushroomFood = FoodMushroom NS_SWIFT_UNAVAILABLE<br>
};<br>
<br>
but NS_SWIFT_UNAVAILABLE can’t be used in this case.<br>
<br>
So the only thing I seem to be able to do is #define the old names to the new names:<br>
#define dairyFood FoodDairy<br>
etc etc<br>
<br>
which hides them from the generated interface, but exposes those defines to the rest of the code and in a few cases caused unwanted substitutions to happen.<br>
<br>
Is a non-#define way of doing this possible?<br>
<br>
Cheers<br>
<br>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>