Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing argument arrayLiteral in call

I have a dictionary defined as:

var options: Dictionary <String, AnyObject>?

When I try to call

Array(options?.keys)

I get this error:

Missing argument label 'arrayLiteral:' in call

How do I get the keys out of my dictionary?

like image 448
quantumpotato Avatar asked Dec 27 '25 18:12

quantumpotato


2 Answers

Object constructors (i.e. init()s) in Swift require a name for each argument, so you need to call Array(arrayLiteral: options?.keys). You probably have to unwrap the optional, though.

like image 146
NRitH Avatar answered Dec 30 '25 11:12

NRitH


One answer is that you are passing it an optional value instead of a regular / non-optional value.

This works:

var options: Dictionary <String, AnyObject>?
Array(options!.keys)

There is more to this though. In a separate case of my own, I have seen this error when creating a set from a literal array of custom objects, but only after I changed the custom object to not inherit from NSObject.

The plot thickens.

like image 27
Chris Conover Avatar answered Dec 30 '25 12:12

Chris Conover



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!