I am trying to read a file in my Bundle using the following code.
let bundle = Bundle(for: type(of: self))
let path = bundle.url(forResource: "file1", withExtension: "xml")!
But path returns nil. I have try Bundle.main, but I get the same error. I have added the files in the bundle by
- drag my file to Xcode and clicks all the targets in the pop up dialog.
- select 'copy items if needed'
- clicks all the targets in the pop up dialog.
I tried to debug, but from the bundle object in the debugger, I can't find a property which shows me what resources it has or not.
Can you please tell me how to fix the issue?
Update: If I manually copy the files (in Macos Finder) to this directory
/Users/john/Library/Developer/Xcode/DerivedData/MyProject/Build/Products/Debug
Then, the swift code can find the file. Can you please tell me what do I need to do to add file to Main Bundle?