NSMenuItem setting state not working
<p>I have a document based app in Swift 1.2. I want to have programmatically generated <code>NSMenuItem</code>'s that have an action to the current NSDocument, and then have that selection get checked. Here's what I have so far:</p>

<p><strong>AppDelegate</strong></p>

<pre><code>// generate items
for thing in thingArray {
    var newThing = NSMenuItem(title:name, action: Selector("myMethod:"), keyEquivalent: "")
    newThing.enabled = true
    submenu.addItem(newThing)
}
</code></pre>

<p><strong>MyDocument</strong></p>

<pre><code>// getting current AppDelegate
let app = NSApplication.sharedApplication().delegate as! AppDelegate

// called by user selected menu item
@IBAction func myMethod(sender: NSMenuItem) {
    let parent = sender.parentItem!

    // iterate through all Items to setState: NSOffState

    for item in parent.submenu!.itemArray as! [NSMenuItem] {
        if workspace?.name == item.title {
            item.state = NSOnState     
            break
        }
    }
}
</code></pre>

<p>I know that all the code up to the <code>item.state</code> is working. I put print logs to test it. But what happens is usually the menu item doesn't get checked, but occasionally it does. </p>

<p>My best guess is that the menu isn't refreshing but I am not sure how to do it.  Could it also be that the <code>NSMenuItem</code>'s action is being sent through the First Responder chain? Any help would be greatly appreciated.</p>