Read plist in swift 3 playground

前端 未结 2 2035
栀梦
栀梦 2021-01-14 09:45

I have followed loads of questions here but nothing seems to work.

I am using Swift3 in a Playground. Running on El Capitan and Xcode 8.1.

2条回答
  •  一个人的身影
    2021-01-14 10:31

    You are using the wrong API, you need to load Data rather than something in the file system.

    if let url = Bundle.main.url(forResource: "levelList", withExtension: "plist"),
       let plistData = try? Data(contentsOf: url ) {
          let mydata = try! PropertyListSerialization.propertyList(from: plistData, options: [], format: nil) as! [String:Any]
    }
    

提交回复
热议问题