Dictionary

public extension Dictionary where Value == Any

Available where Value == Any

  • Returns the value associated with the specified key casted to T (the type of the default value), or the specified default value if the key didn’t have a value or if it couldn’t be casted to T.

    Uses autoclosure so your default value won’t be created if it’s not needed.

    Warning

    This will raise a runtime assertion error if there is a value in the dictionary but it’s not of the same time as the default value. For that case, you should handle it some other way.

    Declaration

    Swift

    func castedValue<T>(forKey key: Key, or defaultValue: @autoclosure () -> T) -> T