使用 [[NSBundle mainBundle] resourcesPath] 中的路径

发布于 2024-08-15 14:03:19 字数 357 浏览 3 评论 0原文

我确信这是一个非常基本的问题,但我很难找到任何相关内容。

假设我的应用程序位于一个文件夹中,还有更多文件夹中,如下所示:

  • MainFolder >二级文件夹> AppBundle.app>所有的东西

然后,我想做的是访问“MainFolder”中的文件。我知道我可以使用以下方法获取 AppBundle 的路径:

NSLog(@"%@",[[NSBundle mainBundle]资源路径]);

我不确定的是如何获取“MainFolder”的路径。

任何指点都会很棒!

谢谢, 汤姆

I'm sure it's a very basic problem, but I'm having trouble finding anything about it.

Say I've got my app in a folder, in some more folders, like this:

  • MainFolder > SecondaryFolder > AppBundle.app > all the stuff

Then, what I want to do is access a file that is in the "MainFolder". I know I can get the path of the AppBundle by using:

NSLog(@"%@",[[NSBundle mainBundle] resourcePath]);

What I'm uncertain about is how to get the path of the "MainFolder".

Any pointers would be great!

Thanks,
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

棒棒糖 2024-08-22 14:03:19

我会使用 -[NSString stringByDeletingLastPathComponent] 两次。

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];

I'd use -[NSString stringByDeletingLastPathComponent] twice.

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
三生殊途 2024-08-22 14:03:19

我用:
NSString *mainBundlePath = [[NSBundle mainBundle]bundlePath];

I use:
NSString *mainBundlePath = [[NSBundle mainBundle] bundlePath];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文