0

感谢您回答我的问题。我有信心我会得到一些有价值的反馈和对我的查询的答复。请找到以下代码。这是将数据保存在服务器中的方法,

-(NSMutableString *) saveChanges 
{
    NSMutableString *changes = [[NSMutableString alloc] init];
    NSString *completeXml = [[NSString alloc]init];

    for (NSString *key in objectToModify)
    {
        BaseModel *orig = [savedOriginalObject objectForKey:key];
        BaseModel *new = [objectToModify objectForKey:key];

        BaseModel *nested = Nil;

        // BaseModel was added
        if (orig == nil)
        {
            nested = [ModelReferences referenceNested:new];
            nested.EntityState = [[EntityState alloc] initWithIntValue:Added];
            NSMutableString *newXml = [self createObjectToXML:nested];
            completeXml = [completeXml stringByAppendingString:newXml];
        }

        // BaseModel might be modified
        else {
                BaseModel *newNested = [ModelReferences referenceNested:new];
                BaseModel *origNested = [ModelReferences referenceNested:orig];

                NSMutableString *newXml = [self createObjectToXML:newNested];
                NSMutableString *origXml = [self createObjectToXML:origNested];

                completeXml = [completeXml stringByAppendingString:newXml];

                if (![newXml isEqualToString:origXml]) 
                {
                    nested = newNested;
                    nested.EntityState = [[EntityState alloc] initWithIntValue:Modified];
                }

            }

        if (nested != Nil)
            [changes appendString:[self createObjectToXML:nested]];
    }

    //refreshes both dictionaries (objectToModify and savedOriginalObject) 
    [self refreshSavedOriginalObject:completeXml];


    if ([changes length] > 0)
        return changes;
    else
        return Nil;
}

每当我进行任何更改时,它都会被保存,但是当我想添加新数据或对象时,它不会保存在服务器中。例如,我想在添加对象NSMutableDictionary后添加它没有被保存。如果我必须提供有关我的编码的更多信息,请告诉我。

4

1 回答 1

0

解决方法是.. 通过为给定的基本模型生成 UUID,一旦生成 UUID,基本模型循环会将其视为非原件并将其作为新 UUID 并创建一个位置.. 因此基本模型与新的 UUID 将被发送到服务器并同时保存。

于 2013-04-08T19:13:35.913 回答