[swift-users] Equivalent of NS_SWIFT_UNAVAILABLE for non-methods?
    Matteo 
    matteo at mimecastercentral.com
       
    Wed Jul  6 05:03:47 CDT 2016
    
    
  
Suppose I have an existing enum in Obj-C such as:
typedef NS_OPTIONS(NSInteger, FoodType)
{
    dairyFood   = 1 << 0,
    meatFood    = 1 << 1,
    mushroomFood = 1 << 2
};
I want to rename all the values so that swift code can use the shorter names. i.e
typedef NS_OPTIONS(NSInteger, FoodType)
{
    FoodDairy = 1 << 0,
    FoodMeat = 1 << 1,
    FoodMushroom = 1 << 2
};
generates:
public struct FoodType : OptionSetType {
    public init(rawValue: Int)
 
    public static var Dairy: FoodType { get }
    public static var Meat: FoodType { get }
    public static var Mushroom: FoodType { get }
}
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.
At first I thought this would suffice:
typedef NS_OPTIONS(NSInteger, FoodType)
{
    FoodDairy = 1 << 0,
    FoodMeat = 1 << 1,
    FoodMushroom = 1 << 2,
// Old names
dairyFood = FoodDairy,
meatFood = FoodMeat,
mushroomFood = FoodMushroom 
};
but that prevents the generated interface using the shortened names since all the values don’t follow the same pattern:
public struct FoodType : OptionSetType {
    public init(rawValue: Int)
    
    public static var FoodDairy: FoodType { get }
    public static var FoodMeat: FoodType { get }
    public static var FoodMushroom: FoodType { get }
    
    public static var dairyFood: FoodType { get }
    public static var meatFood: FoodType { get }
    public static var mushroomFood: FoodType { get }
}
I was looking for something similar to NS_SWIFT_UNAVAILABLE such that I could do:
typedef NS_OPTIONS(NSInteger, FoodType)
{
    FoodDairy = 1 << 0,
    FoodMeat = 1 << 1,
  FoodMushroom = 1 << 2,
  
  // Old names
  dairyFood = FoodDairy NS_SWIFT_UNAVAILABLE,
  meatFood = FoodMeat NS_SWIFT_UNAVALIBLE,
  mushroomFood = FoodMushroom NS_SWIFT_UNAVAILABLE
};
but NS_SWIFT_UNAVAILABLE can’t be used in this case.
So the only thing I seem to be able to do is #define the old names to the new names:
#define dairyFood   FoodDairy
etc etc
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.
Is a non-#define way of doing this possible?
Cheers
    
    
More information about the swift-users
mailing list