Swift switch 你所不知道用法 switch case let accessory as HMAccessory
程序员文章站
2024-01-03 09:37:40
...
官方Demo
func append(object: AnyObject) {
switch object {
case let actionSet as HMActionSet:
actionSets.append(actionSet)
actionSets = actionSets.sortByTypeAndLocalizedName()
case let accessory as HMAccessory:
accessories.append(accessory)
accessories = accessories.sortByLocalizedName()
case let room as HMRoom:
rooms.append(room)
rooms = rooms.sortByLocalizedName()
case let zone as HMZone:
zones.append(zone)
zones = zones.sortByLocalizedName()
case let trigger as HMTrigger:
triggers.append(trigger)
triggers = triggers.sortByLocalizedName()
case let serviceGroup as HMServiceGroup:
serviceGroups.append(serviceGroup)
serviceGroups = serviceGroups.sortByLocalizedName()
default:
break
}
}