nsindexset

Objective-C: How to convert NSIndexSet to NSIndexPath

烂漫一生 提交于 2020-06-26 05:03:34
问题 I would like to convert NSIndexSet Object to NSIndexPath,as effect as link: https://developer.apple.com/reference/photos/phphotolibrarychangeobserver?language=objc - (void)photoLibraryDidChange:(PHChange *)changeInfo { // Photos may call this method on a background queue; // switch to the main queue to update the UI. dispatch_async(dispatch_get_main_queue(), ^{ // Check for changes to the displayed album itself // (its existence and metadata, not its member assets). PHObjectChangeDetails

How to get indexes from NSIndexset into an NSArray in cocoa?

China☆狼群 提交于 2019-12-17 19:58:09
问题 I'm getting the select items from a table view with: NSIndexSet *selectedItems = [aTableView selectedRowIndexes]; what's the best way to get the indexes in a NSArray object? 回答1: Enumerate the set, make NSNumbers out of the indexes, add the NSNumbers to an array. That's how you'd do it. I'm not sure I see the point in transforming a set of indexes into a less efficient representation, though. To enumerate a set, you have two options. If you're targeting OS X 10.6 or iOS 4, you can use

How to indicate index of NSIndexSet object?

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:09:26
问题 everyone. I want to indicate index of NSIndexSet object. Find various method but I can't find. How to indicate index of NSIndexSet object? NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C",@"A", nil]; NSIndexSet *indexset = [array indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { return [obj isEqual:@"A"]; }]; NSLog(@"%@",[array objectsAtIndexes:indexset]); // I want to indicate index of NSIndexSet object. NSLog(@"%d",[indexset ?]); 回答1: If

Create NSIndexSet from integer array in Swift

独自空忆成欢 提交于 2019-12-06 16:29:34
问题 I converted an NSIndexSet to an [Int] array using the answer at https://stackoverflow.com/a/28964059/6481734 I need to do essentially the opposite, turning the same kind of array back into an NSIndexSet. 回答1: Swift 3 IndexSet can be created directly from an array literal using init(arrayLiteral:), like so: let indices: IndexSet = [1, 2, 3] Original answer (Swift 2.2) Similar to pbasdf's answer, but uses forEach(_:) let array = [1,2,3,4,5,7,8,10] let indexSet = NSMutableIndexSet() array

Create NSIndexSet from integer array in Swift

半世苍凉 提交于 2019-12-04 22:11:41
I converted an NSIndexSet to an [Int] array using the answer at https://stackoverflow.com/a/28964059/6481734 I need to do essentially the opposite, turning the same kind of array back into an NSIndexSet. Alexander Swift 3 IndexSet can be created directly from an array literal using init(arrayLiteral:) , like so: let indices: IndexSet = [1, 2, 3] Original answer (Swift 2.2) Similar to pbasdf's answer , but uses forEach(_:) let array = [1,2,3,4,5,7,8,10] let indexSet = NSMutableIndexSet() array.forEach(indexSet.add) //Swift 3 //Swift 2.2: array.forEach{indexSet.addIndex($0)} print(indexSet) This

NSIndexSet “-indexAtIndex:”?

情到浓时终转凉″ 提交于 2019-11-29 09:16:54
This feels like a dumb question because it seems to me like my use case must be quite common. Say I want to represent a sparse set of indexes with an NSIndexSet (which is of course what it's for). I can use -firstIndex to get the lowest one and -lastIndex for the highest, but what's the canonical way to get a single, arbitrary index in the middle, given its "index"? The docs have left me unclear. E.g. if I have an index set with the indexes { 0, 5, 8, 10, 12, 28 }, and I want to say "give me the fourth index" and I'd expect to get back 10 (or 12 I suppose depending on whether I count the

Get NSIndexSet from NSArray

雨燕双飞 提交于 2019-11-29 03:25:26
问题 NSArray has useful methods to find objects for specified indexes // To find objects by indexes - (id)objectAtIndex:(NSUInteger)index - (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes // To find index by object - (NSUInteger)indexOfObject:(id)anObject However, I want to get NSIndexSet (multiple indexes) for given objects. Something like: - (NSIndexSet *)indexesOfObjects:(NSArray *)objects This method does not exist for NSArray . Am I missing something? Does someone know another standard

Fast enumeration on an NSIndexSet

笑着哭i 提交于 2019-11-28 21:01:56
Can you fast enumerate a NSIndexSet ? if not, what's the best way to enumerate the items in the set? Fast enumeration must yield objects; since an NSIndexSet contains scalar numbers ( NSUInteger s), not objects, no, you cannot fast-enumerate an index set. Hypothetically, it could box them up into NSNumbers, but then it wouldn't be very fast. In OS X 10.6+ and iOS SDK 4.0+, you can use the -enumerateIndexesUsingBlock: message: NSIndexSet *idxSet = ... [idxSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { //... do something with idx // *stop = YES; to stop iteration early }]; A

How to get indexes from NSIndexset into an NSArray in cocoa?

亡梦爱人 提交于 2019-11-28 11:57:50
I'm getting the select items from a table view with: NSIndexSet *selectedItems = [aTableView selectedRowIndexes]; what's the best way to get the indexes in a NSArray object? Enumerate the set, make NSNumbers out of the indexes, add the NSNumbers to an array. That's how you'd do it. I'm not sure I see the point in transforming a set of indexes into a less efficient representation, though. To enumerate a set, you have two options. If you're targeting OS X 10.6 or iOS 4, you can use enumerateIndexesUsingBlock: . If you're targeting earlier versions, you'll have to get the firstIndex and then keep

NSIndexSet “-indexAtIndex:”?

主宰稳场 提交于 2019-11-28 02:43:50
问题 This feels like a dumb question because it seems to me like my use case must be quite common. Say I want to represent a sparse set of indexes with an NSIndexSet (which is of course what it's for). I can use -firstIndex to get the lowest one and -lastIndex for the highest, but what's the canonical way to get a single, arbitrary index in the middle, given its "index"? The docs have left me unclear. E.g. if I have an index set with the indexes { 0, 5, 8, 10, 12, 28 }, and I want to say "give me