지금은 Orphaned objects
의 삭제로 고심하고 있습니다. 다음과 같은 수업을했습니다.restKit에서 고아 개체 삭제 0.20
내 모든 RKObjectManagers을 만들어 내 다른 클래스에서 사용이 클래스에서 매퍼 클래스
.
-(RKObjectManager *)mapAppointments{
RKEntityMapping* appointmentMapping = [RKEntityMapping mappingForEntityForName:@"Appointment" inManagedObjectStore:managedObjectStore];
appointmentMapping.identificationAttributes = @[@"app_id",@"app_start"] ;
[appointmentMapping addAttributeMappingsFromDictionary:@{
@"AddressInfo": @"app_addressinfo",
@"Completed": @"app_completed",
@"Description": @"app_description",
@"EndDate":@"app_end",
@"FullDay": @"app_fullday",
@"Id":@"app_id",
@"Label": @"app_label",
@"LabelId": @"app_label_id",
@"Location": @"app_location",
@"Private":@"app_private",
@"ProjectName":@"app_project_name",
@"ProjectNumber": @"app_project_number",
@"RecurrenceInfo": @"app_recurrenceInfo",
@"RelationAddressCity": @"app_relation_address_city",
@"RelationAddressId":@"app_relation_address_id",
@"RelationAddressName": @"app_relation_address_name",
@"RelationAddressStreet":@"app_relation_address_street",
@"RelationCode": @"app_relation_code",
@"RelationContactPersonId": @"app_relation_contact_id",
@"RelationContactPersonName": @"app_relation_contact_name",
@"RelationName":@"app_relation_name",
@"ReminderInfo":@"app_reminder_info",
@"StartDate": @"app_start",
@"State": @"app_state",
@"Subject": @"app_subject",
@"SupplierCode":@"app_supplier_code",
@"SupplierContactPersonId": @"app_supplier_contact_person_id",
@"SupplierContactPersonName":@"app_supplier_contact_person_name",
@"SupplierName": @"app_supplier_name",
@"Type": @"app_type",
@"ResxPers":@"app_resxPers",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:appointmentMapping pathPattern:nil keyPath:@"" statusCodes:[NSIndexSet indexSetWithIndex:200]];
NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor,nil];
[objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
return objectManager;
}
내 요청을하고 또한 고아 개체를 삭제하려고이 클래스에서 WebService 클래스
.
-(void)fetchAppointmentsOnCompletionFor:(NSDate *)start andEnd:(NSDate *)end OnCompletion:(myCompletion) compblock{
Mapper *mapper = [Mapper new];
RKManagedObjectStore *store = [[AdsolutDataModel sharedDataModel] objectStore];
NSLog(@"store is %@",store);
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
RKObjectManager *objectManager = [mapper mapAppointments];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *strStart = [dateFormatter stringFromDate:start];
NSString *strEnd = [dateFormatter stringFromDate:end];
NSString *userName = [[NSUserDefaults standardUserDefaults]valueForKey:@"userName"];
NSString *hash = [[NSUserDefaults standardUserDefaults]valueForKey:@"hash"];
NSString *urlString = [NSString stringWithFormat:@"getcrmappointments?gebrcode=%@&token=%@&startdate=%@&enddate=%@",userName,hash,strStart,strEnd];
[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:urlString];
NSDictionary *argsDict = nil;
BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
if (match) {
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Appointment"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(app_start >= %@) AND (app_end <= %@)", start,end]; // NOTE: Coerced from string to number
fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"app_id" ascending:YES] ];
return fetchRequest;
}
return nil;
}];
NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil];
RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"REQUEST URL = %@",request.URL);
NSError *error = nil;
BOOL success = [context save:&error];
if (!success) RKLogWarning(@"Failed saving managed object context: %@", error);
NSLog(@"SUCCESS");
NSError *saveError = nil;
for (Appointment *appointment in mappingResult.array) {
NSLog(@"Appointment title is %@",appointment.app_subject);
appointment.synchronized = @1;
appointment.app_delete = @0;
[context saveToPersistentStore:&saveError];
}
[self fetchAfwezighedenOnCompletionFor:start andEnd:end OnCompletion:^(BOOL finished) {
if(finished){
compblock(YES);
}
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}];
[objectManager enqueueObjectRequestOperation:operation];
}
순간
문제는 Orphaned objects
은 삭제되지 않습니다. 나 somehting 잘못하고 있습니까 아니면 뭔가가 바로 설정되지 않습니다?
도움 주셔서 감사합니다.
을 기록됩니다 페치 요청 블록을 변경
시도? 가져 오기 블록이 실행됩니까? 달리면 패턴이 일치합니까? 왜 매니저가 요청을하는 대신'RKManagedObjectRequestOperation'을 명시 적으로 사용하고 있습니까? – Wain
@Wain 늦게 답변 해 주셔서 감사합니다. 하지만 fetch 블록이 실행되지 않는 것 같습니다. 이것이 가능한 방법 Anny 아이디어? – Steaphann