我需要知道Swift语言是否可以通过某种方式来实现标记枚举的某些元素的功能。例如,我在Swift枚举中有一组属性,其中一些属性可以设置动画,而另一些则不能。我想要类似的东西:
public enum Property: String {
case prop1,
case prop2 @animatable,
case prop3 @animatable,
case prop4,
case prop5 @animatable,
...
...
...
case prop100
}
然后在函数中,我可以传递一个参数,例如:
func animate(_ prop: Property @animatable, startTime:CFTimeInterval, duration:CFTimeInterval) {
}
因此,我传递了一个属性,该属性是枚举的元素,只能进行动画处理,而不能进行其他操作。有没有一种干净的方法可以在Swift语言(Swift 5)中实现类似的目的?