gpt4 book ai didi

ios - 应用程序在第二次运行 nsnull 计数的循环时崩溃

转载 作者:行者123 更新时间:2023-11-28 18:05:53 25 4
gpt4 key购买 nike

我有一个循环,第一次运行良好,但第二次运行时我得到:

-[NSNull count]: unrecognized selector sent to instance 0x3a094a70
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull count]: unrecognized selector sent to instance 0x3a094a70'

这是我知道它崩溃的代码部分(最后一行):

...
NSLog(@"dict::%@",dictForPost);
// collect the photo urls in an array
photosInDict = [NSArray array];

// photos is an array of dictionaries in the dictionary
photosInDict = dictForPost[@"photos"];
if (photosInDict.count) {
....

我知道当 photosInDict 在 dic 中没有图片时它会崩溃,但我不明白为什么,因为我在它上面启动了数组。

最佳答案

 photosInDict = dictForPost[@"photos"]

替换之前分配并存储在 photosInDict 中的对象。因此,之前分配数组没有意义。只是

NSArray * photosInDict = dictForPost[@"photos"];

然后检查

if ([photosInDict isKindOfClass:[NSArray class]]) {
// Yes, it is an array. Do something with it.
if ([photosInDict count]) {
...
}
}

关于ios - 应用程序在第二次运行 nsnull 计数的循环时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20979382/

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