0
它的我的第一個問題提前爲任何錯誤道歉。刪除重複的對象從NSMutableArray與保持排序和所有其他字段
我的問題是刪除重複的值,保持相同的順序,數組有。 就像我陣列格式爲: -
(
{
author = "";
content = "After almost";
"document_name" = "20150108";
"news_id" = 280;
},
{
author = "";
content = "Content";
"document_name" = "20150108"
"news_id" = 282;
}
);
其實即時得到從核心數據這陣,我知道像SetPropertiesToFetch: -
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"news_id"]];
但是從這個我只得到news_id場,但我需要的所有其他領域。 也是我知道的NSSet
NSArray *arrayWithNoDuplicates = [[NSSet setWithArray:papersObject.paperSubject] allObjects];
由於這個我失去了我的排序順序,我在謂詞一樣。
,並同時尋找,我發現enumerateObjectsUsingBlock
NSMutableArray *filteredManagers = [NSMutableArray array];
[managers enumerateObjectsUsingBlock:^(Manager manager, NSUInteger idx, BOOL stop) {
if (![filteredManagers containsObject:manager]) {
[filteredManagers addObject:manager];
}
}];
但在同一篇文章中說,有for循環和塊之間沒有太大的區別。所以我不能使用它,因爲我有數以千計的數據,它不好把循環檢查並從數組中刪除數據。
所以任何人都知道更好的解決方案,刪除重複的對象,並保持排序與字典中的所有其他領域,請讓我知道。
謝謝,非常感謝.both適用於我..... :) –
您的實際問題(重複條目)仍然存在。 – shallowThought