Load files in xcode unit tests

前端 未结 7 1900
失恋的感觉
失恋的感觉 2021-02-02 05:17

I have an Xcode 5 unit test project and some test xml files related to it. I\'ve tried a bunch of approaches but I can\'t seem to load the xml files.

I\'ve tried the fol

7条回答
  •  长发绾君心
    2021-02-02 05:45

    I know this specific question is asking for xml files, but if you're trying to do the same with json files, try this:

    let url = Bundle.main.url(forResource: "data", withExtension: ".json") guard let dataURL = url, let data = try? Data(contentsOf: dataURL) else { fatalError("Couldn't read data.json file") }

提交回复
热议问题