Swift - read plist file to an array?

后端 未结 5 1773
忘掉有多难
忘掉有多难 2021-02-08 10:55

I have created a mini translation from English words to Spanish words. I would like to use the englishArray.plist instead of my englishArray = [\"the cat\"] How can I create thi

5条回答
  •  情深已故
    2021-02-08 11:44

    Swift 4

    The absolute simplest way to do this is

        let url = Bundle.main.url(forResource: "Sounds", withExtension: "plist")!
        let soundsData = try! Data(contentsOf: url)
        let myPlist = try! PropertyListSerialization.propertyList(from: soundsData, options: [], format: nil)
    

    The object myPlist is an Array or Dictionary, whichever you used as the base of your plist.

提交回复
热议问题