How to search an NSSet or NSArray for an object which has an specific value for an specific property?

NSPredicate *predicate = [NSPredicate predicateWithFormat:@”type == %@”, @”standard”]; NSArray *filteredArray = [myArray filteredArrayUsingPredicate:predicate]; id firstFoundObject = nil; firstFoundObject = filteredArray.count > 0 ? filteredArray.firstObject : nil; NB: The notion of the first found object in an NSSet makes no sense since the order of the objects in a set is undefined.

How to create a Core Data predicate to test that a relation contains all given objects?

The following predicate could work: [NSPredicate predicateWithFormat:@”(items.@count == %d) AND (SUBQUERY(items, $x, $x IN %@).@count == %d)”, itemSet.count, itemSet, itemSet.count]; The predicate checks first that the number of items is equal to the size of the given itemSet, and then checks that the number of items which are member of itemSet is also equal to … Read more

How to create array of unique object list in Swift

As of Swift 1.2 (Xcode 6.3 beta), Swift has a native set type. From the release notes: A new Set data structure is included which provides a generic collection of unique elements, with full value semantics. It bridges with NSSet, providing functionality analogous to Array and Dictionary. Here are some simple usage examples: // Create … Read more