[swift-users] Equivalent of NS_SWIFT_UNAVAILABLE for non-methods?

Mark Dalrymple markd at borkware.com
Wed Jul 6 10:47:38 CDT 2016


Another option is to rename them manually:


typedef NS_OPTIONS(NSInteger, FoodType)
{
    dairyFood NS_SWIFT_NAME(dairy)  = 1 << 0 ,
    meatFood NS_SWIFT_NAME(meat)   = 1 << 1 ,
    mushroomFood NS_SWIFT_NAME(mushroomMushroom) = 1 << 2
};


On Wed, Jul 6, 2016 at 6:03 AM, Matteo via swift-users <
swift-users at swift.org> wrote:

> 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
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160706/618dfb47/attachment.html>


More information about the swift-users mailing list