Swift - read plist file to an array?

后端 未结 5 1772
忘掉有多难
忘掉有多难 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:34

    Change your root object to Array, then

    var myEnglishArray: [String] = []
    if let URL = NSBundle.mainBundle().URLForResource("englishArray", withExtension: "plist") {
          if let englishFromPlist = NSArray(contentsOfURL: URL) as? [String] {
            myEnglishArray = englishFromPlist
          }
        }
    

提交回复
热议问题