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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With