gpt4 book ai didi

ios - __NSArrayM 插入对象 :atIndex:]; object cannot be nil

转载 作者:行者123 更新时间:2023-11-28 20:01:54 25 4
gpt4 key购买 nike

我是 iOS 开发的新手。我想做加密和解密。我的问题如下:当我运行我的代码时,解密在模拟器中运行良好,但它没有在 iPhone 设备上运行。我收到如下所示的错误消息:

[__NSArrayM insertObject:atIndex:]: object cannot be nil

这是我的代码。我定义了一个包含多个字符串的数组:

<dictionary>
<array>
<string>india,chennai,salem,coimbatore,krishnagiri,hosur,palghat</string>
<string>india1,chennai1,salem1,coimbatore1,krishnagiri1,hosur1,palghat1</string>
</array>
</dictionary>

NSString *stringIndex1 = [[NSString alloc]init];
NSMutableArray *arrAthigaaramList1;
dictDecryptList=[[NSMutableDictionary alloc]init];

for(int i=0;i<[arrD_Chapter count];i++)//50 Chapter wise
{
stringIndex1 = [arrD_Chapter objectAtIndex:i];
NSData *b64DecData = [Base64 decode:stringIndex1];
NSData *decryptedData = [[NSData alloc]init];
decryptedData= [b64DecData AESDecryptWithPassphrase:@"mypassword"];
NSString *decryptedStr = [[NSString alloc] initWithData:decryptedData encoding:NSUTF32StringEncoding];

NSLog(@"Decryped Data Base 64 encoded = %@",decryptedStr);

[arrAthigaaramList1 addObject:decryptedStr];
}

这段代码有什么问题?

最佳答案

您应该执行以下操作:

NSString *stringIndex1 = [[NSString alloc]init];
NSMutableArray *arrAthigaaramList1 = [[NSMutableArray alloc] init];
dictDecryptList=[[NSMutableDictionary alloc]init];

for(int i=0;i<[arrD_Chapter count];i++)//50 Chapter wise
{
stringIndex1 = [arrD_Chapter objectAtIndex:i];
NSData *b64DecData = [Base64 decode:stringIndex1];
NSData *decryptedData = [[NSData alloc]init];
decryptedData= [b64DecData AESDecryptWithPassphrase:@"mypassword"];
NSString *decryptedStr = [[NSString alloc] initWithData:decryptedData encoding:NSUTF32StringEncoding];

if (decryptedStr) {
NSLog(@"Decryped Data Base 64 encoded = %@",decryptedStr);
[arrAthigaaramList1 addObject:decryptedStr];
} else {
NSLog(@"ERROR decrypting!!!");
}


}

这会让你做两件事:

1) 初始化可变数组。2) 解密并记录错误后,不要尝试插入 nil 字符串。

关于ios - __NSArrayM 插入对象 :atIndex:]; object cannot be nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23656517/

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