iPhone 应用程序从文件内容中抛出 EXC_BAD_ACCESS 和字典
我在应用程序的 applicationDidFinishLaunching
方法中包含代码
NSArray *paths = [[NSArray alloc]
initWithArray:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)];
NSString *docsDirectory = [[NSString alloc] initWithString:[paths objectAtIndex:0]];
NSLog(@"This app's documents directory: %@",docsDirectory);
NSString *docsDirectoryWithPlist = [[NSString alloc] initWithFormat:@"%@/Stuff.plist", docsDirectory];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:docsDirectoryWithPlist isDirectory:NO];
if (fileExists)
{
chdir([docsDirectory UTF8String]);
NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];
,每当到达最后一行时,它就会崩溃,并一路抛出 EXC_BAD_ACCESS
。
提前致谢!
I have the code
NSArray *paths = [[NSArray alloc]
initWithArray:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)];
NSString *docsDirectory = [[NSString alloc] initWithString:[paths objectAtIndex:0]];
NSLog(@"This app's documents directory: %@",docsDirectory);
NSString *docsDirectoryWithPlist = [[NSString alloc] initWithFormat:@"%@/Stuff.plist", docsDirectory];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:docsDirectoryWithPlist isDirectory:NO];
if (fileExists)
{
chdir([docsDirectory UTF8String]);
NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];
in an application's applicationDidFinishLaunching
method and whenever it gets to the last line it crashes, throwing EXC_BAD_ACCESS
along the way.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此行尝试从捆绑目录中读取文件。从完整路径读取文件:
This line tries to read file from the bundle directory. Read file from full path: