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!

Nirav D
  • 71,513
  • 12
  • 161
  • 183
R S
  • 73
  • 8
  • Possible duplicate of [Parsing JSON using Swift 3](http://stackoverflow.com/questions/39458836/parsing-json-using-swift-3) – Andy Ibanez Sep 18 '16 at 03:51
  • Compare http://stackoverflow.com/questions/39549107/swift-3-type-any-has-no-subscript-members/39549477#39549477 – Jans Sep 18 '16 at 05:48

1 Answers1

1

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

let items = Array(todoDictionary.values) as! [[String: Any]]
Nirav D
  • 71,513
  • 12
  • 161
  • 183