nsset

Why doesn't NSOrderedSet inherit from NSSet?

走远了吗. 提交于 2019-12-02 15:44:05
Surely an ordered set is a more-specific case of a set, so why does NSOrderedSet inherit from NSObject rather than NSSet ? I went through the interface of NSSet and you're right, ordered sets appear to satisfy the Liskov substitution principle and could therefor inherit from NSSet . There is one little method that breaks this: mutableCopy . The return value of mutableCopy must be an NSMutableSet , but NSMutableOrderedSet should inherit from NSOrderedSet . You can't have both. Let me explain with some code. First, let's look at the correct behaviour of NSSet and NSMutableSet : NSSet* immutable

using NSPredicate with a set of answers

落爺英雄遲暮 提交于 2019-12-01 17:29:35
问题 I have a set of strings containing personIDs and I have a NSFetchedResults of people managedObjects with unique strPersonIDs. I tried to create an NSPredicate but it fails. Any help with this would be greatly appreciated. I'm a bit new to NSPredicate so be kind. NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]]; searchString = [NSString stringWithFormat:@"(strPersonID IN %@)",zipSet]; NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:searchString]; The

SKSpriteNode pools in iOS 8 seem to be allocated to overlapping memory

安稳与你 提交于 2019-12-01 07:34:57
I might be missing something. But my current app on the appstore works in iOS 7, but in iOS 8 completely fails because it won't create a preallocated pool of sprites. They appear to be written to the same address unless the sprites have specifically different properties. In iOS 7 the following code produces a set with 4 unique objects. In iOS 8, the same code produces a set with only 1 object: NSMutableSet *aSet = [NSMutableSet set]; SKColor *sameColor = [SKColor redColor]; CGSize sameSize = CGSizeMake(10, 10); for (int i = 0; i < 4; i++) { //allocate a brand new sprite SKSpriteNode

SKSpriteNode pools in iOS 8 seem to be allocated to overlapping memory

蓝咒 提交于 2019-12-01 04:16:49
问题 I might be missing something. But my current app on the appstore works in iOS 7, but in iOS 8 completely fails because it won't create a preallocated pool of sprites. They appear to be written to the same address unless the sprites have specifically different properties. In iOS 7 the following code produces a set with 4 unique objects. In iOS 8, the same code produces a set with only 1 object: NSMutableSet *aSet = [NSMutableSet set]; SKColor *sameColor = [SKColor redColor]; CGSize sameSize =

Create a NSSet from NSArray based on property

不问归期 提交于 2019-12-01 03:53:48
How does one create a NSSet of objects from an array based on a property. 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"]]; A dictionary essentially has this functionality already. Its keys are a set, so you can create the dictionary to hold the objects, keyed by whatever attribute you're interested in: [NSDictionary dictionaryWithObjects

Create a NSSet from NSArray based on property

拟墨画扇 提交于 2019-12-01 00:59:29
问题 How does one create a NSSet of objects from an array based on a property. 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. 回答1: NSSet *distinctSet = [NSSet setWithArray:[array valueForKeyPath:@"@distinctUnionOfObjects.property"]]; 回答2: A dictionary essentially has this functionality already. Its keys are a set, so you can create the

Combinations of different NSArray objects

ぃ、小莉子 提交于 2019-12-01 00:39:11
I want to find the combinations of the elements in diffrent arrays . Let say I've three NSArray objects as: NSArray *set1 = [NSArray arrayWithObjects:@"A",@"B",@"C", nil]; NSArray *set2 = [NSArray arrayWithObjects:@"a",@"b", nil]; NSArray *set3 = [NSArray arrayWithObjects:@"1",nil]; Now the required answers is following arrays NSArray *combinations = [{A},{B},{C},{a},{b},{1},{A,a},{A,b},{A,1},{B,a},{B,b},{B,1},{a,1},{b,1},{A,a,1},{A,b,1},{B,a,1},{B,b,1},{C,a,1},{C,b,1}]; Edit Currently I've did the following code and I'm able to get combinations of two length. NSArray *set1 = [NSArray

How to turn an NSArray of strings into an array of unique strings, in the same order?

自古美人都是妖i 提交于 2019-11-30 10:39:36
问题 If you have an NSArray of strings { @"ONE", @"ONE", @"ONE", "TWO", @"THREE", @"THREE" } How would I turn that into { @"ONE", @"TWO", @"THREE" } ..where the array follows the same order as the original. I think that you can turn an array into an NSSet to get unique items, but if you turn it back into an array you are not guaranteed to get the same order.. 回答1: My initial thought was that you could do: NSArray * a = [NSArray arrayWithObjects:@"ONE", @"ONE", @"ONE", @"TWO", @"THREE", @"THREE",

What is the most efficient way to sort an NSSet?

隐身守侯 提交于 2019-11-30 06:41:29
问题 What's the most efficient way to sort objects in an NSSet / NSMutableSet based on a property of the objects in the set? Right now the way I am doing it is by iterating through each object, add them to a NSMutableArray , and sort that array with NSSortDescriptor . 回答1: try using [[mySet allObjects] sortedArrayUsingDescriptors:descriptors]; Edit : For iOS ≥ 4.0 and Mac OS X ≥ 10.6 you can directly use [mySet sortedArrayUsingDescriptors:descriptors]; 回答2: The "most efficient way" to sort a set

NSDictionary, NSArray, NSSet and efficiency

我的梦境 提交于 2019-11-30 05:25:12
I've got a text file, with about 200,000 lines. Each line represents an object with multiple properties. I only search through one of the properties (the unique ID) of the objects. If the unique ID I'm looking for is the same as the current object's unique ID, I'm gonna read the rest of the object's values. Right now, each time I search for an object, I just read the whole text file line by line, create an object for each line and see if it's the object I'm looking for - which is basically the most inefficient way to do the search. I would like to read all those objects into memory, so I can