数据未保存在服务器中

时间:2013-03-16 12:09:25

标签: iphone ios6

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

-(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中的对象。如果我必须提供有关我的编码的更多信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

修复是..通过为给定的Base模型生成UUID,一旦生成UUID,基本模型循环将把它视为非orig并将其作为新的UUID并创建一个位置。因此具有新UUID的基本模型将被发送到服务器并同时保存。