ios – Restkit在映射时添加自定义值

ios – Restkit在映射时添加自定义值,第1张

概述Restkit映射和插入数据工作正常,但我需要向数据库添加自定义值(而不是从 JSON) RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:entityName inManagedObjectStore:managedObjectStore];[entityMapping addAttribute Restkit映射和插入数据工作正常,但我需要向数据库添加自定义值(而不是从 JSON)

RKEntityMapPing *entityMapPing = [RKEntityMapPing mapPingForEntityForname:entityname inManagedobjectStore:managedobjectStore];[entityMapPing addAttributeMapPingsFromDictionary:dict];if (uniqKey != nil) {    entityMapPing.IDentificationAttributes = @[ uniqKey ];}// Set MIME Type to JsONmanager.requestSerializationMIMEType = RKMIMETypeJsON;// register mapPings with the provIDer using a response descriptorRKResponseDescriptor *responseDescriptor =[RKResponseDescriptor responseDescriptorWithMapPing:entityMapPing                                             method:RKRequestMethodPOST                                        pathPattern:path                                            keyPath:rootKeyPath                                        statusCodes:[NSIndexSet indexSetWithIndex:200]];[manager addResponseDescriptor:responseDescriptor];[manager postObject:nil path:path parameters:queryParams success:^(RKObjectRequestoperation *operation,RKMapPingResult *mapPingResult) {if (mapPingResult.array.count != 0) {    NSDictionary *data = mapPingResult.array[0];           NSLog(@"data: %@",data);      }else{    NSLog(@"Unable to fetch data from: %@",path);}} failure:^(RKObjectRequestoperation *operation,NSError *error) {    NSLog(@"Error response': %@",error);}];

除了nspredict和过滤数据之外,是否可以在映射时手动插入值(如字符串)?

解决方法 您可以在完成块中修改映射结果中的对象,但是您需要显式保存上下文,并且上下文的其他观察者将收到保存通知.这是超级简单的方法.

或者,您可以覆盖willSave或使用NSManagedobjectContextwillSaveNotification(后者是更好的选项)来触发您的自定义逻辑.然后,您的更改将与RestKit更改一起内联,并将自动保存.

总结

以上是内存溢出为你收集整理的ios – Restkit在映射时添加自定义值全部内容,希望文章能够帮你解决ios – Restkit在映射时添加自定义值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1077064.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存