开发者

Cocoa: get path to Contents/Resources folder in cocoa bundle

开发者 https://www.devze.com 2023-03-28 04:00 出处:网络
I am aware of how to get a specific file from the Resources fo开发者_开发问答lder in cocoa, i.e. :

I am aware of how to get a specific file from the Resources fo开发者_开发问答lder in cocoa, i.e. :

NSBundle* myBundle = [NSBundle mainBundle];
NSString* myImage = [myBundle pathForResource:@"Seagull" ofType:@"jpg"];

anyways, I'd like to have a simple function that gives me the path to the Resources folder so I can use it in c++ like this.

String getResourcePath()
{
    return the correct path here
}

std::ofstream theFile;
theFile.open(getResourcePath()+"test.txt");

I guess I could manually combine the main bundle name with Contents/Resources, anyways I'd like to know if there is a more robust solution!

Thanks!


If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before asking the question here at SO.

In this case, the answer is this method. But let me reiterate:

If you ever wonder if an Apple-provided class has a certain method, do look up Apple's own documentation before asking the question here at SO.

And, when you do so, go over all the methods in the documentation. That way, you'll learn what kind of methods are available.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号