0

I added an NSDictionary to NSMutableArray.

for (TblFiles *objTblFile in visitorFilesArray) {
        NSData *fileDataTemp = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: objTblFile.internalFileName]];
        NSDictionary *tempDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:(NSInteger)objTblFile.fileID],@"fileID",
                                  objTblFile.fileName,@"fileName",
                                  fileDataTemp,@"fileData",nil];
        [filesArrayInAddVisitor addObject:tempDict];
}

After that I tried to delete one dictionary from this array, I am getting crash. It happens because of fileID values are changed. Some time its working perfect. Some times getting crash.

 NSPredicate *objPredicate = [NSPredicate predicateWithFormat:@"fileID == %@",151];
 NSArray *filterArray = [filesArrayInAddVisitor filteredArrayUsingPredicate:objPredicate];

[self->filesArrayInAddVisitor removeObject:[filterArray objectAtIndex:0]];
[self->fileTableView reloadData]; 

I don't know why values are changed in NSDictionary.

Example : I added fileID as 151, but in NSMutableArray it changed to zero in some cases.

phani
  • 105
  • 2
  • 15
  • see this for help :[https://stackoverflow.com/questions/1295459/are-keys-and-values-in-an-nsdictionary-ordered(Are keys and values in an NSDictionary ordered?) – Anbu.Karthik Dec 10 '19 at 10:40
  • "@"fileID == %@",151", that's not compiling. Are you using a `NSNumber` or a NSString for the value in the predicate because in the dictionary it's said to be a NSNumber. Also, you need to be more explicit. Is it because you didn't find the value after filtering? – Larme Dec 10 '19 at 10:50
  • @lame predicate is working fine. But fileID value in NSDictionary is changed. – phani Dec 10 '19 at 10:58

1 Answers1

0

1.First problem i got for crash is the predicate string. replace it with this

NSPredicate *objPredicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"fileID == %d",151]];

2.You are saying that fileID value got change then first confirm that what is the type of objTblFile.fileID if it is NSInteger then its ok.

For my example i have passed NSInteger there and code working fine.

Sagar koyani
  • 403
  • 2
  • 12