0
當我從核心數據中搜索保存的數據時,它在提取舊數據時會給我保存的數據。需要幫助來查找我的錯誤無法從核心數據中提取保存的數據
- (void)retrieveDataFromCoreData
{
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"VitaminData" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error = nil;
NSArray *objects = [context executeFetchRequest:request
error:&error];
NSString *matchFound = nil;
matches = [[NSMutableArray alloc]init];
if ([objects count] == 0) {
//matchFound = @"No matches";
} else {
matches = objects[0];
matchFound = [matches valueForKey:@"userdetails"];
}
NSLog("retrieved data : %@",matchFound);
}
檢查數組中的其他對象,而不僅僅是第一個。 – wootage
你不是在這裏搜索。每次只提取第一個對象。要搜索,請將'NSPredicate'設置爲'NSFetchRequest'指定條件。 – Akhilrajtr
謝謝你的回覆球員 – suneel