After deleting the
typealiasand replacing it with a class of the same name, we didn’t have to worry about changing function definitions and property types all throughout our codebase. We made the changes locally, in one file, and most all the rest of our code still compiled. Pretty cool! Here’s the relevant portion of the pull request that made that change.
Any time you use the same tuple type more than once, consider making a
typealias. In this case, the code became a lot shorter and easier to skim and understand.
Objective-C developers, burdened with arcane syntax for blocks, use C’s
typedefto isolate that syntax strangeness in one place. And even though Swift’s closure syntax is awesome, we can still benefit from Objective-C’s example – we can use type aliases for closure signatures.
I recommend using a descriptive
typealiasthat is private to your file, and then extending that
typealiasso you can keep things neat and tidy. […] We’re still extending the view controller, but specifically we’re extending the
typealiasso that the extension has a helpful name. This is another way that
typealiascan help add semantic meaning to your code.
Too bad Swift extensions can’t be named directly, like Objective-C categories.
Stay up-to-date by subscribing to the Comments RSS Feed for this post.