17

我确信这是一个非常基本的问题,但我很难找到任何关于它的东西。

假设我将我的应用程序放在一个文件夹中,在更多文件夹中,如下所示:

  • MainFolder > SecondaryFolder > AppBundle.app > 所有的东西

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

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

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

任何指针都会很棒!

谢谢,汤姆

4

2 回答 2

31

我会用-[NSString stringByDeletingLastPathComponent]两次。

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
于 2009-12-23T00:07:39.310 回答
5

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

于 2013-05-07T16:18:35.393 回答