Swift 3 - Bundle.main.path在不同目录中具有相同的文件名

时间:2021-08-21 16:36:58

Long story short, I have two settings files that must have the same name. They're currently in separate folders, something like:

长话短说,我有两个必须具有相同名称的设置文件。它们目前位于不同的文件夹中,例如:

Resources/brand/dev/settings.file
Resources/brand/prod/settings.file

However I can't seem to get Swift to grab the file out, it always comes up as nil

但是我似乎无法让Swift抓住文件,它总是以零为单位

var file = Bundle.main.path(forResource:"settings", ofType:"file", inDirectory:"Resources/brand/dev")

If I remove one of the files, and the inDirectory parameter everything works fine.

如果我删除其中一个文件,并且inDirectory参数一切正常。

File target membership, project build phases all look OK.

文件目标成员资格,项目构建阶段看起来都很好。

Am I missing something here?

我在这里错过了什么吗?

1 个解决方案

#1


1  

Setting files must be added to XCode with the option 'Create folder references'

必须使用“创建文件夹引用”选项将设置文件添加到XCode

#1


1  

Setting files must be added to XCode with the option 'Create folder references'

必须使用“创建文件夹引用”选项将设置文件添加到XCode