gpt4 book ai didi

iphone - NSMutableArray 删除重复项

转载 作者:行者123 更新时间:2023-12-03 20:21:04 25 4
gpt4 key购买 nike

 NSLog(@"Ci sono %d categorie",category.count);
for(int c=0; c<category.count; c++){
CategoryArray * element =[category objectAtIndex:c];
NSLog(@"******************************");
NSLog(@"Titolo %@",element.label);
NSLog(@"Source %@",element.url);
NSLog(@"******************************");
[element release];

这是我的代码!我需要删除所有重复数组...我使用此代码,但我不明白为什么它不起作用。

uniquearray = [[NSSet setWithArray:category] allObjects];

最佳答案

你的代码确实有效。试试这个:

NSArray *a = [NSArray arrayWithObjects:@"a", @"b", @"c", @"d", @"b", @"b", @"d", nil];
NSLog(@"a: %@\ndistinctA: %@", a, [[NSSet setWithArray:a] allObjects]);

输出为:

a: (
a,
b,
c,
d,
b,
b,
d
)
distinctA: (
c,
d,
a,
b
)

知道代码适用于包含重复对象的数组,您现在必须想知道为什么您认为重复的对象被认为不是如此。关于 hash 和 isEqual 的现有答案为您指明了正确的方向。

关于iphone - NSMutableArray 删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7307854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com