Swift switch 你所不知道用法 switch case let accessory as HMAccessory

官方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
        }
    }

Swift switch 你所不知道用法 switch case let accessory as HMAccessory_第1张图片

你可能感兴趣的:(iOS,Swift,switch,swift,case-let)