업데이트 :대량 갱신 및 가끔 삽입 (coredata) - 너무 느린
나 '..
여기에 지혜 혜택을 누릴 수, Comparing Two Arrays안녕 얘들 아 : 현재 NSSET의 minusSet 링크로보고 처음 응용 프로그램에서 Coredata를 사용하여, 데이터 파일을 다운로드하고 500 개의 객체 (각각 60 개의 속성이 있음)를 삽입합니다. - 빠르고, 아무런 문제가 없습니다.
각 후속 시작 파일의 업데이트 된 버전을 다운로드합니다. 여기에서 모든 기존 개체의 속성 (5 속성 제외)을 업데이트하고 다운로드 한 파일에 추가 된 항목에 대해 새 속성을 만들어야합니다.
그래서, 처음 실행 나는
내가 두 배열, 기존 하나 다운로드 하나를 만들 ... 500 개체가 ... 일주일 후 내 파일이 지금은 507 개 항목을 포함 말할 수. 각 배열의 개수가 동일한 경우
NSArray *peopleArrayDownloaded = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeopleTemp];
NSArray *peopleArrayExisting = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeople];
후, 난 그냥 이렇게 :
는NSUInteger index = 0;
if ([peopleArrayExisting count] == [peopleArrayDownloaded count]) {
NSLog(@"Number of people downloaded is same as the number of people existing");
for (person *existingPerson in peopleArrayExisting) {
person *tempPerson = [peopleArrayDownloaded objectAtIndex:index];
// NSLog(@"Updating id: %@ with id: %@",existingPerson.person_id,tempPerson.person_id);
// I have 60 attributes which I to update on each object, is there a quicker way other than overwriting existing?
index++;
}
} else {
NSLog(@"Number of people downloaded is different to number of players existing");
이제 느린 부분을 온다.
내가 사용 결국이 (어떤이 tooooo 느리게) :
NSLog(@"Need people added to the league");
for (person *tempPerson in peopeArrayDownloaded) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person_id = %@",tempPerson.person_id];
// NSLog(@"Searching for existing person, person_id: %@",existingPerson.person_id);
NSArray *filteredArray = [peopleArrayExisting filteredArrayUsingPredicate:predicate];
if ([filteredArray count] == 0) {
NSLog(@"Couldn't find an existing person in the downloaded file. Adding..");
person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"person" inManagedObjectContext:managedObjectContextPeople];
내 다운로드 한 파일에서 추가 항목을 참조 인덱스 항목의 새로운 배열을 생성하는 방법이 있나요?
부수적으로, 내 tableViews에서 NSFetchedResultsController를 사용하여 속성을 업데이트하면 [셀 setNeedsDisplay]; .. 셀당 약 60 회, 좋은 것은 아니며 앱을 중단시킬 수 있습니다. 읽기
감사합니다 :) 나는 여전히 코어 데이터 프레임 워크를 사용하여 새로운 해요,하지만 내 생각 엔이 문제가 루프 당신이 게시 한에 달려 있다는 것을 말함으로써 시작하겠습니다
참고 : 선택자에서 이름없는 인수를 사용하는 것은 좋지 않습니다. – retainCount
댓글을 주셔서 감사합니다. 아직 배우고 있습니다. 내가 어디에서 이러는거야? – iOSDevil