根据属性从NSArray创建NSSet [英] Create a NSSet from NSArray based on property
本文介绍了根据属性从NSArray创建NSSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何基于属性从数组中创建对象的NSSet
.
How does one create a NSSet
of objects from an array based on a property.
例如对象数组,每个对象都强烈引用type
属性,并且数组中存在每种类型的多次出现.如何将其转换为容纳每种类型的单个对象的NSSet
.
e.g. Array of objects, each with a strong reference to a type
property, and multiple occurrences of each type exist in the array. How can this be turned into an NSSet
holding a single object of each type.
推荐答案
NSSet *distinctSet = [NSSet setWithArray:[array valueForKeyPath:@"@distinctUnionOfObjects.property"]];
这篇关于根据属性从NSArray创建NSSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文