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
,添加它沒有得到保存後。請讓我知道,如果我必須提供更多關於我的編碼的信息。
解決方法是..通過生成用於給定基本模型中的UUID,一旦產生UUID,示範基地循環會考慮它作爲一個沒有原稿,並使其作爲一個新的UUID,並創建一個位置..因此,具有新UUID的基本模型將被髮送到服務器並同時保存... – 2013-04-08 19:12:27