Type_Casting
Type Casting
Forced type casting (as!)
Conditional type casting (as?)
medium | type-casting-in-swift
how-to-convert-a-string-to-a-custom-type-in-swift
Dictionary Types Casting
Converting from [String: Any] => [String: String]
Using LosslessStringConvertible in
- Bool
- Double
- Float
- Float80
- Path
- Substring
- Unicode.Scalar
String(describing: CustomStringConvertible)
let people: [String: Any] = ["Taylor": 178.0, "Justin": 175, "Ed": 173.23, "Nick": true, "Lexton": "Son"]
let peopleValue = people.mapValues { String(describing: $0) }
// ["Nick": "true", "Taylor": "178.0", "Justin": "175", "Ed": "173.23", "Lexton": "Son"]
converting-string-any-to-string-string
Converting to Data
let cafe: Data? = "Café".data(using: .utf8) // non-nil