在可可应用程序资源文件夹路径 [英] Resources folder path in cocoa app

查看:141
本文介绍了在可可应用程序资源文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作而使用一些C文件的Mac OS X应用程序,和我有一个配置文件,我将它添加到应用程序的资源。

I am working on Mac OS X app which using some c files, and i have a configuration file i add it to the app resources.

我的问题是什么是资源文件夹中的相对路径?

My question is "What is the relative path of resources folder?"

我试过

[MyAppName]。应用程序/内容/资源/的config.cfg

和只有当我运行从X code我的应用程序,它工作正常,否则就不起作用!

and it works fine only when I run my app from xCode, otherwise it's doesn't work!

我以为该应用从MacOS的文件夹开始,所以我用这个路径:
../资源/的config.cfg

I thought the app starts from "MacOS" folder, so i used this path: "../Resources/config.cfg"

但它也没有工作:(

任何帮助,请

推荐答案

使用相对路径是自找麻烦。幸运的是可可会给你一个绝对路径:

Using relative paths is asking for trouble. Fortunately Cocoa will give you an absolute path:

NSBundle *myBundle = [NSBundle mainBundle];
NSString *absPath= [myBundle pathForResource:@"config" ofType:@"cfg"];

这篇关于在可可应用程序资源文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆