In C#, you can write a function that takes any enumeration value as an argument by declaring the argument as type Enum
, like so...
public enum FirstEnum
{
A,
B,
C
}
public enum SecondEnum
{
D,
E,
F
}
public void StoreValue(Enum key, object value)
{
myDictionary[key] = value; <-- Uses the enum as a key
}
StoreValue(FirstEnum.A, someItem); // Using the first enum type
StoreValue(SecondEnum.D, someItem); // Using the second enum type
StoreValue("Sam", someItem); // Won't compile since 'Sam' is not an enum
Can you do something similar in Swift? I know you can declare the argument someEnum
as a string and use it that way, but I'm trying to find out if it can be enforced to be an Enum like you can in C#.