简体   繁体   English

Xcode:工作区中的所有项目都可以使用文件吗?

[英]Xcode: Is it possible to have files available to all projects within a workspace?

I have added a JSON file to the workspace, outside of any projects. 我在任何项目之外都向工作空间添加了一个JSON文件。 I would like this file to be available to all projects that I add to the workspace. 我希望此文件可用于我添加到工作区的所有项目。

When I try to do the following, I get a Cocoa Error 258: 当我尝试执行以下操作时,出现可可错误258:

NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"json"];


NSError *error;
NSString *json = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

if (!error) {
    NSLog(@"%@", json);
} else {
    NSLog(@"%@", [error localizedDescription]);
}

What's the proper way of sharing a single file in a workspace across many projects? 在多个项目中的工作空间中共享单个文件的正确方法是什么?

At the target in your project there are 6 tabs. 在项目的目标位置,有6个选项卡。 Go to build phases and check at Copy Bundle Resource whether or not that file is added to your new targets bundle. 转到构建阶段,并在“复制捆绑包资源”中检查该文件是否已添加到新的目标捆绑包中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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