aryaxt
aryaxt

Reputation: 77616

Swift - extra argument 'count' in call?

All I'm trying to do is to inverse key/values in a dictionary, and I get the following error:

extra argument 'count' in cal

var dictionary = SWIFT_DICTIONARY

var inverseDictionary = NSDictionary.dictionaryWithObjects(dictionary?.keys, forKeys: dictionary?.values, count: dictionary?.count)

Upvotes: 0

Views: 1110

Answers (1)

Antonio
Antonio

Reputation: 72760

Use this instead:

var inverseDictionary = NSDictionary(objects: dictionary.keys.array, forKeys: dictionary.values.array)

I notice that you are unwrapping dictionary in your code, but it is declared as non optional. Code mistake or just copy & paste mistake?

Addendum - if you try the static version without the count parameter:

var inverseDictionary = NSDictionary.dictionaryWithObjects(dictionary.keys.array, forKeys: dictionary.values.array)

the compiler complains with this message:

'dictionaryWithObjects(_:forKeys:) is unavailable: use object construction 'NSDictionary(objects:forKeys:)'

I think the same happens for the other method you want to use, but the compiler doesn't report the proper error message.

Upvotes: 4

Related Questions