0
我正在從Dictionary獲取數據。它運作良好,並將數據存儲在NSMutableArray中我希望在將對象添加到需要之前確保Array不包含具有相同名稱和類型的同一對象。請看下面。如何在添加新值之前檢查數組是否具有相同的對象值
在插入對象之前,如果不需要插入,我們應該檢查它是否包含Type和Name對象。
NSArray *resultDic = [result1 objectForKey:@"results"];
for (int i = 0; i<[resultDic count]; i++) {
id item = [resultDic objectAtIndex:i];
NSDictionary *jsonDict = (NSDictionary *) item;
GetData *theObject =[[GetData alloc] init];
NSString*error = [jsonDict valueForKey:@"error"];
if(![error isEqualToString:@"No Record Found."])
{
[theObject setVaccineID:[jsonDict valueForKey:@"ID"]];
[theObject setVaccineName:[jsonDict valueForKey:@"Name"]];
[theObject setVaccinationType:[jsonDict valueForKey:@"Type"]];
[theObject setVaccineType:[jsonDict valueForKey:@"VType"]];
[theObject setFarmName:[jsonDict valueForKey:@"FName"]];
[theObject setDay:[jsonDict valueForKey:@"Day"]];
[theObject setAddedDateTime:[jsonDict valueForKey:@"DateTime"]];
[appDelegate.dataArray addObject:theObject];
}
}
答案>> https://stackoverflow.com/questions/10387582/checking-an-array-if-it-contains-an-object-by-a-specific-property-objective-c –
您可以通過使用containsObject.Check進行檢查,下面的鏈接可能對您有用https://stackoverflow.com/a/6299064/5184217 –