Member-only story
Type Placeholders: A Look at the New Swift 5.6 Feature
Type placeholders were recently introduced in Swift 5.6. Get in touch with a new useful Swift feature.

Type placeholders were recently introduced in Swift 5.6. And yes, they are a nice add-on to the powerful Swift-type inference system. If you are familiar with C++, you must know about an auto
keyword. Type placeholders are almost the same.
Generics and type placeholder
let number: _ = 42 // Type placeholder
let anotherNumber = 42
Yes, Swift can infer a variable’s type, but type placeholders mean to be used for a type with multiple types in it. Generics. That’s where they really shine.
Consider regular Result
enum
enum Result<Success, Failure> where Failure : Error {
case success(Success)
case failure(Failure)
}
And what if we have some kind of complex object
var ohMy = [1: [3: (1, 2, 3, "That's a long tuple")]]
If you will try to create a Result
from ohMy
, you'll see compilation error.
let result = Result.success(ohMy)
Note: Generic parameter
Failure
could not be inferred