我是 ObjectiveC 和 Xcode 的新手并且会犯错误。这段代码从 getAllRecords 中获取了一个字典(myDataPlist)。然后,我在 (myDataPlist) 中制作一个字典(1 条记录)的可变副本,并用它解密 1 个字段。这完美地工作。我只返回那个记录(mutCopy)。这也有效。我的问题是原始字典(myDataPlist)的更改。它被解密的记录也在(myDataPlist)中被解密。2 NSLog(@"%@",myDataPlist) 返回不同的结果。我肯定错过了什么。为什么 (myDataPlist) 会发生变化?
谢谢您的帮助。
-(NSDictionary *)getRecordForKey:(NSString *)key{
NSDictionary *myDataPlist = [self getAllRecords];
NSMutableDictionary *mutCopy = [[myDataPlist valueForKey:key] mutableCopy];
NSArray *keys = [mutCopy allKeys];
NSData *tData = [[NSData alloc]init];
NSLog(@"%@",myDataPlist);
for (int x = 0; x <= [keys count] - 1; x++) {
if (![keys[x] isEqualToString:@"Template"] && ![keys[x] isEqualToString:@"RecNum"]) {
NSMutableArray *myArray = [mutCopy objectForKey:keys[x]];
tData = myArray[1];
NSString *tString = [tData decryptData:tData withKey:self.settingsManager.masterPad];
myArray[1] = tString;
[mutCopy setObject:myArray forKey:keys[x]];
}
}
NSLog(@"%@",myDataPlist);
return mutCopy ;
}