gpt4 book ai didi

iphone - 异常的 NSLog() 导致崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 01:39:03 25 4
gpt4 key购买 nike

有谁知道以下原因导致程序崩溃的原因吗?

    NSFileManager *filemgr;
NSString *currentpath = [filemgr currentDirectoryPath];
NSArray *filelist;

filemgr = [NSFileManager defaultManager];

filelist = [filemgr contentsOfDirectoryAtPath:currentpath error:nil];
int count=[filelist count];

for (int i = 0; i < count ; i++)
NSLog (@"%@", [filelist objectAtIndex: 1]);

作为补充说明,我正在重定向 NSLog()。

最佳答案

我认为您的崩溃消息来自您要求当前目录的第二行。但是,您在第 4 行分配了变量,这可能是它崩溃的原因。相反,您应该将您的代码重新排列成这样。

NSFileManager *filemgr = [NSFileManager defaultManager];    
NSString *currentpath = [filemgr currentDirectoryPath];

据我所见,您首先声明了所有变量,这就是发生错误的原因。在 Objective-C 中,在何处声明变量并不重要,但在使用它们之前必须对其进行分配和初始化。

关于iphone - 异常的 NSLog() 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9028159/

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