感谢您回答我的问题。我有信心我会得到一些有价值的反馈和对我的查询的答复。请找到以下代码。这是将数据保存在服务器中的方法,
-(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
后添加它没有被保存。如果我必须提供有关我的编码的更多信息,请告诉我。