Xcode Copy Bundle Resources 找不到文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16010452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:13:17  来源:igfitidea点击:

Xcode Copy Bundle Resources can't find files

iphoneiosxcodestoryboardresourcebundle

提问by d3p0nit

Xcode can't find my Storyboards and my Info.plist in my Copy Bundle Resources, So my App doesn't run. I tried to add the Existing files again but they always appear red highlighted. I'm pretty sure it must be a local problem because when i clone the latest update from my repository on my other mac its runs without any problems. I already tried to re-install Xcode, delete files from Xcode/DerivedDataand i also deleted the com.apple.Xcode.plist. Anyone any ideas?

Xcode 在我的Copy Bundle Resources 中找不到我的 Storyboards 和我的 Info.plist ,所以我的应用程序无法运行。我尝试再次添加现有文件,但它们总是以红色突出显示。我很确定这一定是本地问题,因为当我从我的另一台 Mac 上的存储库克隆最新更新时,它的运行没有任何问题。我已经尝试重新安装 Xcode,从Xcode/DerivedData 中删除文件,我还删除了com.apple.Xcode.plist。有人有什么想法吗?

回答by Vostro162

Try to reset your Simulator and then clean your App Build Folder

尝试重置您的模拟器,然后清理您的应用程序构建文件夹

回答by Wilbo Baggins

My experience is that the proposed solution works, but cleaning and re-compiling the entire app whenever a resource has changed is very tedious, especially for larger projects.

我的经验是,建议的解决方案有效,但在资源发生变化时清理和重新编译整个应用程序非常繁琐,尤其是对于较大的项目。

Therefore I came up with this solution that forces fresh resources in the app on a per-directorybasis, without having to clean or recompile:

因此,我想出了这个解决方案,它可以在应用程序中按目录强制使用新资源,而无需清理或重新编译:

  1. Add a 'Run Script Build Phase' (Editor > Add Build Phase > Add Run Script Build Phase)
    1. Copy/paste the following script into the build phase (don't forget to set the actual paths on line 1):
  1. 添加“运行脚本构建阶段”(编辑器 > 添加构建阶段 > 添加运行脚本构建阶段)
    1. 将以下脚本复制/粘贴到构建阶段(不要忘记在第 1 行设置实际路径):


dirsToCopy=("path1/directory1","path2/directory2")

for INPATTERN in "${dirsToCopy[@]}"; do
    INDIR=$PROJECT_DIR/$INPATTERN/*
    OUTDIR=$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/$INPATTERN
    cp -R $INDIR $OUTDIR
done


For those not used to working with shell scripts:

对于那些不习惯使用 shell 脚本的人:

  • paths on line 1 of the script are relative to the project directory (where the .xcodeproj file resides)

  • you can add more (or less) paths to the array dirsToCopyif you want

  • you can change the pattern of files to copy where variable INDIRis defined

  • you can change how the copying is done (currently, recursive due to -R) by changing the flags to cpin the last line of script within the for block.

  • 脚本第 1 行的路径相对于项目目录(.xcodeproj 文件所在的位置)

  • 您可以添加更多(或更少)的路径数组dirsToCopy,如果你想

  • 您可以更改文件模式以复制INDIR定义变量的位置

  • 您可以-R通过cp在 for 块内脚本的最后一行更改标志来更改复制的完成方式(当前,递归由于)。