nsset

Does NSSet's containsObject: test for pointer equality or value equality?

核能气质少年 提交于 2019-12-03 14:35:40
问题 Say I have an NSSet with a string in it. If I send containsObject: with another string which is a different pointer but the exact same string value, will that return YES ? Also, is it the same story when it comes to removeObject: ? I.e., different objects with different pointers but the same string values will cause removal? 回答1: -containsObject: uses -isEqual: (and -hash ) for equality testing. This applies to -removeObject: as well, and any other operations in NSSet that depend on some

Ordered Sets and Core Data (NSOrderedSet)

≡放荡痞女 提交于 2019-12-03 13:44:46
问题 I have a list of share prices with the properties dateTime and value . Currently I am sorting the share prices when fetching them using a sort descriptor. Now, I would like to change my code and store them in already sorted order to faster retrieve the most current share price (dateTime = max). I am inserting the share prices one by one using SharePrice *priceItem= [NSEntityDescription insertNewObjectForEntityForName:@"SharePrice" inManagedObjectContext:context]; How can I sort the share

NSPredicate find object with attribute in NSSet

£可爱£侵袭症+ 提交于 2019-12-03 12:44:26
I have an NSMangedObject that contains NSSet of other NSManagedObjects . I need to check if these objects has an value in NSSet and then return them. I use MagicalRecord for fetching data. So I need something like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringObjects contains %@", string]; So if NSSet stringObjects contains some string that I am looking for so then return object I have requested. One note here: stringObjects (name just for example it represent my NSSet ) it is NSSet that contains NSManagedObjects, so I need to search them by some id (for example

Does NSSet's containsObject: test for pointer equality or value equality?

匆匆过客 提交于 2019-12-03 04:20:33
Say I have an NSSet with a string in it. If I send containsObject: with another string which is a different pointer but the exact same string value, will that return YES ? Also, is it the same story when it comes to removeObject: ? I.e., different objects with different pointers but the same string values will cause removal? -containsObject: uses -isEqual: (and -hash ) for equality testing. This applies to -removeObject: as well, and any other operations in NSSet that depend on some notion of equality. 来源: https://stackoverflow.com/questions/8410606/does-nssets-containsobject-test-for-pointer

Ordered Sets and Core Data (NSOrderedSet)

自闭症网瘾萝莉.ら 提交于 2019-12-03 03:07:17
I have a list of share prices with the properties dateTime and value . Currently I am sorting the share prices when fetching them using a sort descriptor. Now, I would like to change my code and store them in already sorted order to faster retrieve the most current share price (dateTime = max). I am inserting the share prices one by one using SharePrice *priceItem= [NSEntityDescription insertNewObjectForEntityForName:@"SharePrice" inManagedObjectContext:context]; How can I sort the share prices right after inserting them using a sort descriptor on dateTime ? Or would I need to convert it to a

How to return an NSMutableArray from an NSSet

安稳与你 提交于 2019-12-03 02:30:59
问题 I'm able to put the contents of an NSSet into an NSMutableArray like this: NSMutableArray *array = [set allObjects]; The compiler complains though because [set allObjects] returns an NSArray not an NSMutableArray . How should this be fixed? 回答1: Since -allObjects returns an array, you can create a mutable version with: NSMutableArray *array = [NSMutableArray arrayWithArray:[set allObjects]]; Or, alternatively, if you want to handle the object ownership: NSMutableArray *array = [[set

Why doesn't NSOrderedSet inherit from NSSet?

Deadly 提交于 2019-12-03 02:12:41
问题 Surely an ordered set is a more-specific case of a set, so why does NSOrderedSet inherit from NSObject rather than NSSet ? 回答1: 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

Creating an array from properties of objects in another array

限于喜欢 提交于 2019-12-03 00:45:46
问题 Is there any convenient way to take an array/set of objects and create a new array/set containing some property of each item in the first array? For example, an array contains Car objects. I need an array of licensePlates, where each car has an NSObject car.licensePlate. Currently I just iterate through the first array adding objects to my mutable results array, but was wondering if there is an instantiation method that exists for this (checked the docs for NSArray). 回答1: This will return an

Creating an array from properties of objects in another array

只愿长相守 提交于 2019-12-02 16:09:18
Is there any convenient way to take an array/set of objects and create a new array/set containing some property of each item in the first array? For example, an array contains Car objects. I need an array of licensePlates, where each car has an NSObject car.licensePlate. Currently I just iterate through the first array adding objects to my mutable results array, but was wondering if there is an instantiation method that exists for this (checked the docs for NSArray). This will return an array containing the value of licensePlate from each item in the myCars array: NSArray *licensePlates =

How to return an NSMutableArray from an NSSet

北慕城南 提交于 2019-12-02 16:02:22
I'm able to put the contents of an NSSet into an NSMutableArray like this: NSMutableArray *array = [set allObjects]; The compiler complains though because [set allObjects] returns an NSArray not an NSMutableArray . How should this be fixed? Since -allObjects returns an array, you can create a mutable version with: NSMutableArray *array = [NSMutableArray arrayWithArray:[set allObjects]]; Or, alternatively, if you want to handle the object ownership: NSMutableArray *array = [[set allObjects] mutableCopy]; I resolved crashing by using NSMutableArray's method 'addObjectsFromArray' to assign all