R S
R S

Reputation: 73

Type Any has no subscript members Error in Swift 3.0?

I am following this tutorial here...

And the issue I am having is I keep getting the error.

"Type Any has no subscript members Error" in this function...

func allItems() -> [TodoItem] {
let todoDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) ?? [:]
let items = Array(todoDictionary.values)
return items.map({TodoItem(deadline: $0["deadline"] as! NSDate, title: $0["title"] as! String, UUID: $0["UUID"] as! String!)}).sort({(left: TodoItem, right:TodoItem) -> Bool in
        (left.deadline.compare(right.deadline) == .OrderedAscending)
}

The error is being generated on this line...

return items.map({TodoItem(deadline: $0["deadline"] as! NSDate, title: $0["title"] as! String, UUID: $0["UUID"] as! String!)}).sort({(left: TodoItem, right:TodoItem) -> Bool in
        (left.deadline.compare(right.deadline) == .OrderedAscending)}

I am completely stumped.

Any help would be appreciated! Thank you!

Upvotes: 0

Views: 1228

Answers (1)

Nirav D
Nirav D

Reputation: 72420

You need to explicitly specify the type of items object as [[String:Any]].

let items = Array(todoDictionary.values) as! [[String: Any]]

Upvotes: 1

Related Questions