Eric
Eric

Reputation: 161

What does the arrow ( -> ) between two types mean in 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?

Upvotes: 8

Views: 13907

Answers (3)

Kid Limonade
Kid Limonade

Reputation: 80

success : AnyObject -> Void

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

Upvotes: 4

Paramasivan Samuttiram
Paramasivan Samuttiram

Reputation: 3738

Syntax for closure expression separates Argument and Return type with a return arrow ->.

Upvotes: 0

Jon Purdy
Jon Purdy

Reputation: 54971

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

Upvotes: 11

Related Questions