Articles, podcasts and news about Swift development, by John Sundell.

Using typealiases to reduce the length of method signatures

Published on 23 Jan 2017

One thing that I find really useful in Swift is to use typealiases to reduce the length of method signatures in generic types:

public class PathFinder<Object: PathFinderObject> {
    public typealias Map = Object.Map
    public typealias Node = Map.Node
    public typealias Path = PathFinderPath<Object>
    public static func possiblePaths(
        for object: Object,
        at rootNode: Node,
        on map: Map
    ) -> Path.Sequence {
        return .init(object: object, rootNode: rootNode, map: map)

Support Swift by Sundell by checking out this sponsor:

Genius Scan SDK

Genius Scan SDK: Add a powerful document scanner to any iOS app. Genius Scan’s SDK features advanced image processing that’s the result of over 10 years of research and development and can be fully customized and integrated into your app with just one line of code. Mention Swift by Sundell when requesting a free demo to get a 20% discount on your license for a whole year.