bennett bennett - 11 months ago 71
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


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