I have a dictionary where key is string and value is array of strings.
var someItems : [String: [String]] = [String: [String]]()
I am trying to get item by it's index...
var temp = someItems[0]
But I am gettings error:
'subscript' is unavailable: cannot subscript String with an Int
I don't understand why this doesn't work?
Dictionary
是基于key
的而不是基于index
的,并且键被声明为String
var temp = someItems["key"]
Dictionary items are not sorted and therefore you can't call them with index. You should be able to access its value by writing someItems ["theString"], where theString is the selected key.
try this
if let array = someItems["your key for array"] as NSArray{
print(array)
}
it will return your array for the entered key
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.