/ SWIFT

Using Typealiases with Generics in Swift

Here is a cool detail about Swift typealiases — you can declare the one with a generic type. Great to make your APIs more expressive:

struct Baz {
    typealias Result<T> = Swift.Result<T, Error>
    
    func foo<T>(_ x: T) -> Result<T> {
        return .success(x)
    }
}

Thanks for reading!

If you enjoyed this post, be sure to follow me on Twitter to keep up with the new content. There I write daily on iOS development, programming, and Swift.

Vadim Bulavin

Creator of Yet Another Swift Blog. Senior iOS Engineer at Pluto TV. Coding for fun since 2008, for food since 2012.

Follow