在保存包含 'Calculation' 字段的 PKTItem 时是否有避免错误的解决方法?

Is there a workaround to avoid error when saving PKTItem containing a 'Calculation' field?

如果 PKTItem 包含 'Calculation' 字段,save() 失败:

item["owner"] = myProfile
item.save()
.onSuccess {(savedItem : PKTItem!) in
    print("new owner is me: \(myProfile.name)")
}
.onError {error in
    print("Error: \(error.localizedDescription)")
}

结果为Error: Values cannot be set directly for field with id 126020899126020899为计算字段)

但是,如果 'Calculation' 字段不存在,代码 运行 和 "owner" 字段会更新。

是否根本无法保存包含 'Calculation' 字段的项目?如果没有,我该怎么做呢?

[编辑] 我真正需要的是一种方法来保存对单个字段的更改,而不是在整个 PKTitem 实例上调用 save()。这对我来说最有意义,因为我真的只需要更新一个字段。需要明确的是,我要更新的字段不是 'Calculation' 字段。我试图更改的字段 value 是一个 PKTProfile 实例,它存在于一个 PKTItem 实例中,该实例还包含多个 'Calculation' 字段。如果由我决定,我会去掉 'Calculation' 字段,但它们目前是我们工作流程的重要组成部分。

注意:我的示例基于 PodioPlatformKit SDK. While the PodioPlatformKit is depreciated, this potion is the same in PodioKit. I only use it because it gives examples in Swift rather than Objective-C. The equivalent Objective-C example is here.

中给出的示例

我找到的解决方法非常简单。我在 PKTItem.m 文件中更改了 save 方法,如下所示:

- (PKTAsyncTask *)save {
  __block PKTAsyncTask *task = nil;

  PKTClient *client = [PKTClient currentClient];

  [client performBlock:^{
task = [[PKTApp fetchAppWithID:self.appID] pipe:^PKTAsyncTask *(PKTApp *app) {
  __block PKTAsyncTask *saveTask = nil;

  NSArray *itemFields = [self allFieldsToSaveForApp:app];

  // Filter out all fields of type PKTAppFieldTypeCalculation, which is the 'Calculation' type
  NSMutableArray *mutItemFields = [NSMutableArray new];
    for (PKTItemField* o in itemFields) {
        if ([o type] != PKTAppFieldTypeCalculation) {
            [mutItemFields addObject:o];
        }
    }
    NSArray *filteredItemFields = [mutItemFields copy];
  [client performBlock:^{
    saveTask = [self saveWithItemFields:filteredItemFields];
   }];

  return saveTask;
  }];
 }];
   return task;
 }