Contextual type 'AnyObject' cannot be used with dictionary literal
<p>I have some problems with my Swift project. I am making an app where you can be notified about when you need to take your medicine. </p>

<p>Here is the file where the error code is generated:</p>

<pre><code>import Foundation
import UIKit

class TodoList {
class var sharedInstance : TodoList {
    struct Static {
        static let instance : TodoList = TodoList()
    }
    return Static.instance
}

private let ITEMS_KEY = "todoItems"

func allItems() -&gt; [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, gentag: $0 ["gentag"] as! RepeatInterval, UUID: $0["UUID"] as! String)}).sort({(left: TodoItem, right:TodoItem) -&gt; Bool in
        (left.deadline.compare(right.deadline) == .OrderedAscending)
    })
}

func addItem(item: TodoItem) {
    // persist a representation of this todo item in NSUserDefaults
    var todoDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) ?? Dictionary() // if todoItems hasn't been set in user defaults, initialize todoDictionary to an empty dictionary using nil-coalescing operator (??)
    todoDictionary[item.UUID] = ["deadline": item.deadline, "title": item.title, "gentag": item.gentag.toCalendarUnit(), "UUID": item.UUID] // store NSData representation of todo item in dictionary with UUID as key
    NSUserDefaults.standardUserDefaults().setObject(todoDictionary, forKey: ITEMS_KEY) // save/overwrite todo item list

    // create a corresponding local notification
    let notification = UILocalNotification()
    notification.alertBody = "Hej \"\(item.title)\"Test, husk at tage din medicin: \"\(item.title)\"" // text that will be displayed in the notification
    notification.alertAction = "Skub for at tage medicin" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view"
    notification.fireDate = item.deadline // todo item due date (when notification will be fired)
    notification.soundName = UILocalNotificationDefaultSoundName // play default sound
    notification.userInfo = ["title": item.title, "UUID": item.UUID] // assign a unique identifier to the notification so that we can retrieve it later
    notification.repeatInterval = item.gentag.toCalendarUnit()



    UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

func removeItem(item: TodoItem) {
    for notification in UIApplication.sharedApplication().scheduledLocalNotifications as [UILocalNotification]! { // loop through notifications...
        if (notification.userInfo!["UUID"] as! String == item.UUID) { // ...and cancel the notification that corresponds to this TodoItem instance (matched by UUID)
            UIApplication.sharedApplication().cancelLocalNotification(notification) // there should be a maximum of one match on UUID
            break
        }
    }

    if var todoItems = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) {
        todoItems.removeValueForKey(item.UUID)
        NSUserDefaults.standardUserDefaults().setObject(todoItems, forKey: ITEMS_KEY) // save/overwrite todo item list
    }
}
</code></pre>

<p>Here is the line which generates the error:</p>

<pre><code> todoDictionary[item.UUID] = ["deadline": item.deadline, "title": item.title, "gentag": item.gentag.toCalendarUnit(), "UUID": item.UUID] // store NSData representation of todo item in dictionary with UUID as key
</code></pre>

<p>Here is the error text:</p>

<blockquote>
  <p>Contextual type 'AnyObject' cannot be used with dictionary literal</p>
</blockquote>

<p>Here is my ToDoItem class</p>

<pre><code>import Foundation

struct TodoItem {
    var title: String
    var deadline: NSDate
    var gentag: RepeatInterval
    var UUID: String

   init(deadline: NSDate, title: String, gentag: RepeatInterval, UUID: String) {
        self.deadline = deadline
        self.title = title
        self.gentag = gentag
        self.UUID = UUID
    }

    var isOverdue: Bool {
        return (NSDate().compare(self.deadline) == NSComparisonResult.OrderedDescending) // deadline is earlier than current date
    }
}
</code></pre>