简体   繁体   中英

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

I want to access the path of plist file

在此处输入图片说明

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 ..

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.

构建日志中的复制资源行

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM