我試圖將所有聯繫人備份到服務器上。將一個nsmutable數組的所有對象與另一個nsmutable數組的所有對象進行比較,並將新對象轉換爲另一個nsarray
所以我轉換聯繫人到電子名片串併發送
電子名片串到服務器,並存儲與 的recordId電子名片串到SQLite數據庫所以對於當用戶想在第一時間收回所有的 聯繫人將去到服務器,並在數據庫中。
從第二次我只想發送新聯繫人到 服務器。所以,我需要新的 RecordIds比較存儲 與電話簿RecordIds的NSArray的數據庫RecordIds並獲得到一個數組
比如我有一個像40,41,42,43,44,45 RecordIds到 dbarray。不一定按順序排列。
現在,當用戶增加5組新的聯繫人的電話簿陣列將包含類似40,41,42,43,44,45,46,47,48,50
recordIds所以這次我只是想與recordIds 46,47,48,49和50.Something聯繫人發送類似的增量備份
也是我需要的是檢查是否有存儲vCards.So我還需要比較所有的 任何修改來自 電話簿陣列和數據庫陣列的vCard字符串。
我是新來的iOS編程,我卡住了。請 幫助!!!其緊急
0
A
回答
0
我通過使用下面的代碼解決了上述問題。希望它有助於某人。
-(void)newContactsAndContactsToUpdate
{
NSMutableArray *newContact = [[NSMutableArray alloc]init];
NSMutableArray *newContactRecIds = [[NSMutableArray alloc]init];
NSMutableArray *updateContactRecIds = [[NSMutableArray alloc]init];
NSMutableArray *updateContactRecIds = [[NSMutableArray alloc]init];
//dataArray contains all the contacts(converted into Vcard strings) in the phonebook
//recordIDArray contains the all recordids in the phonebook
//dbArraywithRID contains the recordids stored in database.
//dbArraywithVcard contains contacts(converted into Vcard strings)stored in database
for(int i=0;i< dataArray.count;i++)
{
BOOL found = NO;
int phoneBookRecId=[[recordIDArray objectAtIndex:i] intValue];
NSString * currentPhVc=[dataArray objectAtIndex:i];
for(int j=0;j< dbArraywithRID.count;j++)
{
int dbRecId=[[dbArraywithRID objectAtIndex:j] intValue];
if(dbRecId == phoneBookRecId)
{
found =YES;
NSString * currentDBVc=[dbArraywithVcard objectAtIndex:j];
if(![currentDBVc isEqualToString:currentPhVc])
{
NSLog(@" db rec =%@ - %@ ",currentDBVc,currentPhVc);
[updateContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
[newContact addObject:currentPhVc];
[newContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
}
break;
}
}
if(!found)
{
[newContact addObject:currentPhVc];
[newContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
}
}
if(newContact!=nil && [newContact count] > 0)
{
//newContact array contains all the contacts(vcard strings) that are new
}
if(updateContactRecIds!=nil && [updateContactRecIds count] > 0)
{
updateContactRecIds contains all the recordids which need to be updated
}
}
相關問題
- 1. NSMutable數組對象比較
- 2. 將一個數組中的對象屬性與另一個數組中的對象屬性進行比較
- 3. 將另一個對象與另一個對象(THREE.js r84)的matrix4()進行轉換
- 4. 一個數組進行比較的對象與另一個數組
- 5. 如何將一個對象數組放入另一個對象?
- 6. 將一個數組與一個對象數組進行比較的javascript
- 7. 將數組對象推入另一個數組對象中php
- 8. 將對象[]轉換爲另一個對象[],有可能嗎?
- 9. 將數組中的所有對象合併爲一個
- 10. 在JavaScript中,如何將對象數組與另一個對象數組合並?
- 11. 將所有NSDate對象轉換爲NSString對象的數組
- 12. 如何使用LINQ將數組對象轉換爲另一個?
- 13. 填充JavaScript對象與另一個對象的所有元素
- 14. 將一個對象從一個NSMutable陣列複製到另一個
- 15. 將數組對象轉換爲另一個對象 - 第2部分在javascript中
- 16. 如何將一個對象轉換爲數組對象?
- 17. 如何將genericlist轉換爲一個對象數組 - > [對象]
- 18. 將對象轉換爲具有相同數據的另一個對象? Java
- 19. Java 8 stream將一個數組中的對象替換爲另一個數組
- 20. 將另一個對象轉換爲json的多維對象
- 21. jq:將一個對象數組轉換爲單個對象並將每個數組索引用作新鍵
- 22. 將所有字段從一個對象移動到另一個對象
- 23. 如何讀取並將嵌套對象轉換爲具有所需數據的另一個對象?
- 24. 擁有另一個對象的對象
- 25. 使用jQuery將對象轉換爲另一個對象
- 26. 將IQueryable <T>對象轉換爲另一個對象?
- 27. 將一組對象映射到另一個對象
- 28. 無法將滑塊文本從一個數組對象轉換爲另一個
- 29. 如何將一個json對象轉換爲一個javascript數組
- 30. mongodb:將數組屬性從一個對象複製到另一個對象