bennett bennett - 2 months ago 10x
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.