<div dir="ltr">Another option is to rename them manually:<div><br><div><br></div><div><div>typedef NS_OPTIONS(NSInteger, FoodType)</div><div>{</div><div> dairyFood NS_SWIFT_NAME(dairy) = 1 << 0 ,</div><div> meatFood NS_SWIFT_NAME(meat) = 1 << 1 ,</div><div> mushroomFood NS_SWIFT_NAME(mushroomMushroom) = 1 << 2 </div><div>};</div></div><div><br></div></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>