简体   繁体   中英

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

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. Go to build phases and check at Copy Bundle Resource whether or not that file is added to your new targets bundle.

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