shippo7
shippo7

Reputation: 407

Declaring a function input parameter is equal to nil in Swift

func taskWithMethod(URLString: String, parameters: [String: AnyObject]?, queryParameters: [String: AnyObject]? = nil){}

What is the difference between parameters and queryParameters in this function? Looks like queryParameters is being defined to nil, but I can still pass the queryParameters value to this function.

Upvotes: 0

Views: 65

Answers (1)

Alexander
Alexander

Reputation: 63271

That's a Default Parameter Value (see section "Default Parameter Values"). If no value is passed in, it defaults to nil.

For example, this function can be called like so:

taskWithMethod(URLString: someString, parameters: dict1, queryParameters: dict2)

but it can also be called like so:

taskWithMethod(URLString: someString, parameters: dict1)

in which case queryParameters is set to its default value, nil.

Upvotes: 2

Related Questions