bennett bennett - 1 year ago 109
iOS Question

Swift: Get the Number of Keys In a Dictionary

For swift arrays, we can simply use the

property to find out how many elements are in the collection. However, we can't do the same for dictionary keys. Is the only way to do this to use a for loop and counter?

var myDict: [String: AnyObject] = // ... intialize dictionary with keys and values

myDict.keys.count // doesn't work

Answer Source

There is a count property on dictionary, so myDict.count will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download