gpt4 book ai didi

ios - NSBundle pathForResource : returns nil

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:40 27 4
gpt4 key购买 nike

我正在尝试使用以下代码从 iOS 上的 Xcode 中的支持文件文件夹访问 .txt 文件:

NSString* filePath = @"filename.txt";

NSLog(@"File path: %@", filePath);

NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"txt"];

NSLog(@"File root: %@", fileRoot);

第一个 NSLog 打印出我期望它打印的内容,但最后一个 NSLog 总是简单地打印

File root: (null)

在(尝试)将文件读入内存后访问文件中的文本也只会给我一个(空)打印输出。

这个问题的解决方案可能就在我眼皮底下,我就是找不到。非常感谢任何帮助!提前致谢。

最佳答案

filePath 已包含后缀“.txt”,因此您不能指定它定位资源时再次。要么

NSString* filePath = @"filename.txt";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:nil];

NSString* filePath = @"filename";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"txt"];

关于ios - NSBundle pathForResource : returns nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com