Swift Language Typealias typealias for closures with parameters

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

typealias SuccessHandler = (NSURLSessionDataTask, AnyObject?) -> Void

This code block creates a type alias named SuccessHandler, just in the same way var string = "" creates a variable with the name string.

Now whenever you use SuccessHandler, for example:

func example(_ handler: SuccessHandler) {}

You are essentilly writing:

func example(_ handler: (NSURLSessionDataTask, AnyObject?) -> Void) {}


Got any Swift Language Question?