I have the following code:
class Base {}
class A: Base {}
class B: Base {}
class C: Base {}
func next(obj: Base) -> Base {
if obj is A { return B() }
else if obj is B { return C() }
else if obj is C { return A() }
else { return A() }
}
如何将嵌套的if
语句转换为单个switch
语句?
class X: B
并在其实例上调用next
,它将返回C
,而不是default
情况下的A
。 - Iulian Onofrei