0

如何删除平面数组或json数组中的重复对象

我的数组是这样的

<VideoList2: 0xac46bd0> (entity: VideoList2; id: 0xac64090 <x-coredata://7CD2EB96-C31D-4605-B7AB-13909C6B661B/VideoList2/p982> ; data: {\n Category = Featured;\n Duration = nil;\n image = \"http://files.stora.com/accounts/5053775f0f66021ac50/collection/506c59660023ae100039f/entries/50ae69c00f6602492f001b6f/fields/k509a2cbe0f6602b1/file.jpg\";\n videoLink = \"http://www.youtube.com/v/yf92pV?rel=0\";\n videoName = pamala;\n})",

请帮我。谢谢

4

2 回答 2

0

您可以删除与其他数组相同的NSMutableArray对象

这是删除一个相同的对象

[yourAry removeObject:removingAry];  

并删除所有相同的ary

[yourAry removeObject:removingAry];    

有关更多详细信息,请阅读NSMutableArray 类参考

于 2012-12-14T07:55:37.407 回答
0

如果要从同一数组中删除重复项:

NSMutableArray *mainArray=[[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"A",@"B", nil];

for (NSInteger start=[mainArray count]-1; start>=0; start--) {
    [mainArray removeObjectIdenticalTo:[mainArray objectAtIndex:start] inRange:NSMakeRange(0, start)];
}

NSLog(@"%@",mainArray);

输出:

(
    C,
    D,
    A,
    B
)

如果要删除不同数组中包含的相同对象。

NSMutableArray *mainArray=[[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",@"D", nil];
NSMutableArray *secArray=[[NSMutableArray alloc] initWithObjects:@"B",@"D", nil];

[mainArray removeObjectsInArray:secArray];

NSLog(@"%@",mainArray);

输出:

(
    A,
    C
)
于 2012-12-14T08:06:36.017 回答