1
この関数を使用してNSMenuItemを作成します。それらはすべて2でタグ付けされます。特定のタグを持つNsmenu項目を削除する
func addToComputerInfoMenu (title: String)
{
let addToComputerItem : NSMenuItem = NSMenuItem(title: "\(title)" , action: #selector(openWindow), keyEquivalent: "")
addToComputerItem.attributedTitle = NSAttributedString(string: "\(title)", attributes: [NSFontAttributeName: NSFont.systemFontOfSize(14), NSForegroundColorAttributeName: NSColor.blackColor()])
addToComputerItem.tag = 2
addToComputerItem.enabled = true
computerInfoMenu.addItem(addToComputerItem)
}
"2"タグを持つすべてのアイテムをプログラムで削除したいと思います。 .itemWithTagと.indexOfItemWithTagを使ってみました。私はリストを反復することはできません。
let itemswithindex2 = computerInfoMenu.itemWithTag(2)