Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the arrow ( -> ) between two types mean in Swift?

Tags:

syntax

swift

While researching a separate issue, I came across this SO question: How to create generic closures in Swift

They have a function definition like this:

func saveWithCompletionObject(obj : AnyObject, success : AnyObject -> Void, failure : Void -> Void)

What does the -> in AnyObject -> Void mean?

like image 597
Eric Avatar asked Jan 16 '16 06:01

Eric


2 Answers

It’s a function type. AnyObject -> Void is the type of a function accepting AnyObject and returning Void.

like image 154
Jon Purdy Avatar answered Nov 17 '22 21:11

Jon Purdy


success : AnyObject -> Void

This means that success parameter is a function that receives an object (AnyObject) and returns nothing (Void).

like image 29
Kid Limonade Avatar answered Nov 17 '22 21:11

Kid Limonade