从Info.plist向Dictionary(而不是NSDictionary)添加条目

时间:2014-07-31 10:54:24

标签: dictionary swift nsdictionary

在下面的OS X应用程序中,如何以与创建NSDictionary类似的方式创建Dictionary?

我想我需要在Dictionary上找到一个与NSDictionary(contentsOfFile:infoPlist)执行相同任务的方法,但我不确定这个Dictionary方法是什么。

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
    @IBOutlet weak var window: NSWindow!

    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        var infoPlist = "/Applications/Calendar.app/Contents/Info.plist"

        var nsDictionary = NSDictionary(contentsOfFile:infoPlist)
        println("nsDictionary = \(nsDictionary)")

        var dictionary = Dictionary<String, String>()
        // TODO: How do I add entries from "infoPlist" to "dictionary"
        // like I do above with the old "nsDictionary"?
        println("dictionary = \(dictionary)")
    }

    func applicationWillTerminate(aNotification: NSNotification?) {
    }
}

非常感谢提前。

1 个答案:

答案 0 :(得分:2)

可悲的是,目前在本地快速词典中无法做到这一点。但是使用NSDictionary仍然很好。

有关详细信息,请查看this similar question