【问题标题】:Working with paths from [[NSBundle mainBundle] resourcePath]使用来自 [[NSBundle mainBundle] resourcePath] 的路径
【发布时间】:2023-03-18 07:50:01
【问题描述】:

我确定这是一个非常基本的问题,但我找不到任何相关信息。

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

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

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

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

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

任何指针都会很棒!

谢谢, 汤姆

【问题讨论】:

    标签: objective-c directory path nsbundle


    【解决方案1】:

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

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

    【讨论】:

    • 完美!正是我需要的。非常感谢!
    【解决方案2】:

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

    【讨论】:

    • [[NSBundle mainBundle] bundlePath] 给你包文件本身的路径,如果你想要包内的路径,内容,那么它是[[NSBundle mainBundle] resourcePath]
    猜你喜欢
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    相关资源
    最近更新 更多