hi,
trying to get path to a file in an application bundle in xcode / C project.
Code:
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFBundleRef mainBundle = CFBundleGetMainBundle();
#include <CoreFoundation/CoreFoundation.h>
CFBundleRef mb = CFBundleGetMainBundle();
CFURLRef ur = CFBundleCopyResourceURL(mb, CFSTR("projfile"), CFSTR("bin"), NULL);
-proj1
|->
-Proj1
|->
-Fldr1
|->
-projfile.bin
-main.c
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *bundleURL = [[NSBundle mainBundle] bundleURL];
The structure of your Xcode project isn't necessarily relevant. What's important is the structure within the app-bundle. That is, the code running in the app only sees the structure within the app-bundle. The code doesn't see the Xcode project.Above include line solved the compilation error.Code:#include <CoreFoundation/CoreFoundation.h>
However, CFBundleCopyResourceURL returns null. In my code, I need to know the path the file projfile.bin located so that I can pass it to open file routine.
Code:CFBundleRef mb = CFBundleGetMainBundle(); CFURLRef ur = CFBundleCopyResourceURL(mb, CFSTR("projfile"), CFSTR("bin"), NULL);
I dragged and dropped the Fldr1 to my xcode project. this is my xcode project tree:
Code:-proj1 |-> -Proj1 |-> -Fldr1 |-> -projfile.bin -main.c