Search code examples
swiftxcodepathplist

Get path of file from a SubGroup in project with Swift 5


I want to access the path of plist file

enter image description here

I am accessing path with following line

I can access when file is in root folder with following line

let filePath = Bundle.main.path(forResource: Constants.googleServiceFileName, ofType: "plist")

but when i move files in sub group and use following code its return nil

let filePath = Bundle.main.path(forResource: Constants.googleServiceFileName, ofType: "plist",inDirectory: "Firebase")

but it's return nil ..


Solution

  • The group in which you keep a resource in Xcode is not necessarily related to its final location in the bundle. Your file is probably still in the top level Resources directory.

    If you want to be completely sure where the build puts your file, look for the build log in the Report Navigator, locate the "Copy " line and expand it using the button at the right hand edge. That will tell you exactly where it is.

    A copy resource line from the build log

    In the above, I have an Excel spreadsheet in the group testData. You can see that the build has put it in the top level Resources directory.