ios - 在 restKit 0.20 中删除孤立对象
<p><p>目前我正在努力删除<code>孤立对象</code>。
我有以下类(class)。</p>
<p><strong>映射器类</strong></p>
<p>在这个类中,我创建了我所有的 RKObjectManagers 并在我的其他类中使用它。 </p>
<pre><code>-(RKObjectManager *)mapAppointments{
RKEntityMapping* appointmentMapping = ;
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 = ];
NSArray *arrResponsDescriptor = [initWithObjects:responseDescriptor,nil];
;
return objectManager;
}
</code></pre>
<p><strong>网络服务类</strong></p>
<p>在这个类中,我完成了我的请求,并尝试删除孤立对象。</p>
<pre><code>-(void)fetchAppointmentsOnCompletionFor:(NSDate *)start andEnd:(NSDate *)end OnCompletion:(myCompletion) compblock{
Mapper *mapper = ;
RKManagedObjectStore *store = [ objectStore];
NSLog(@"store is %@",store);
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
RKObjectManager *objectManager = ;
NSDateFormatter *dateFormatter = [init];
];
;
NSString *strStart = ;
NSString *strEnd = ;
NSString *userName = [valueForKey:@"userName"];
NSString *hash = [valueForKey:@"hash"];
NSString *urlString = ;
[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = ;
NSDictionary *argsDict = nil;
BOOL match = tokenizeQueryStrings:NO parsedArguments:&argsDict];
if (match) {
NSFetchRequest *fetchRequest = ;
fetchRequest.predicate = ; // NOTE: Coerced from string to number
fetchRequest.sortDescriptors = @[ ];
return fetchRequest;
}
return nil;
}];
NSURLRequest *request = ;
RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"REQUEST URL = %@",request.URL);
NSError *error = nil;
BOOL success = ;
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;
;
}
[self fetchAfwezighedenOnCompletionFor:start andEnd:end OnCompletion:^(BOOL finished) {
if(finished){
compblock(YES);
}
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [ initWithTitle:@"Error"
message:
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
NSLog(@"Hit error: %@", error);
}];
;
}
</code></pre>
<p><strong>问题</strong></p>
<p>目前,<code>孤立对象</code>并未被删除。我做错了什么还是设置不正确?</p>
<p>感谢您的帮助!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>查看 <code>RKObjectManager managedObjectRequestOperationWithRequest:</code> 的代码表明,获取请求 block 是从传递给操作的对象管理器传递的。因此,需要进行调试才能弄清楚为什么没有调用它。它应该在所有“成功”场景(即响应描述符与接收到的响应匹配的场景)中调用。</p>
<p>您可以考虑使用管理器发出请求而不是获取请求并使用 <code>RKManagedObjectRequestOperation</code>,但理论上这应该只是更少的代码而不是功能上的差异。</p >
<hr/>
<p>尝试更改获取请求 block :</p>
<pre><code>RKPathMatcher *pathMatcher = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在 restKit 0.20 中删除孤立对象,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21375981/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21375981/
</a>
</p>
页:
[1]