且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用restkit忽略已发布对象的空属性

更新时间:2021-11-28 00:43:30

您正在创建一个新的映射,在此行中调用 [selfCompletedAssessmentMapping inverseMapping]:

You are creating a new mapping calling [selfCompletedAssessmentMapping inverseMapping] in this line:

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[selfCompletedAssessmentMapping inverseMapping] objectClass:[CompletedAssessment class] rootKeyPath:nil method:RKRequestMethodPOST];

将其保存到一个变量中,并在创建描述符之前将 assignsDefaultValueForMissingAttributes 赋值给 NO:

Save it to a variable and assign assignsDefaultValueForMissingAttributes to NO before creating the descriptor:

RKObjectMapping *requestMapping = [selfCompletedAssessmentMapping inverseMapping];
requestMapping.assignsDefaultValueForMissingAttributes = NO;
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[CompletedAssessment class] rootKeyPath:nil method:RKRequestMethodPOST];