Read plist in swift 3 playground

前端 未结 2 2011
栀梦
栀梦 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]
    }
    
    0 讨论(0)
  • 2021-01-14 10:35

    To finally get the program working I used.

    devices = NSArray(contentsOfFile: path) as! [AnyObject]
    

    The issue with playground continuously running was solved by going to activity monitor and force quitting the process named com.apple.coresimulator which was identified as not responding. After doing this the playground ran instantly.

    0 讨论(0)
提交回复
热议问题