Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Foundation Collections by Kevin Conner

Foundation Collections by Kevin Conner

Kevin discusses the various collection classes available to Mac and iOS developers as part of Foundation at CocoaHeads August in Raleigh

F13b7ea691e49d2cb953e10317f21976?s=128

Triangle Cocoa

August 23, 2012
Tweet

Transcript

  1. Foundation Collections Kevin Conner @connerk

  2. You know these • NSArray • NSDictionary • NSRange •

    NSNull
  3. New syntax • array[i] • dictionary[k] • @[larry, moe, curly]

    • @{ key: value, foo: bar } • @3, @YES, @(array.count - 1)
  4. Let’s talk about sets baby

  5. NSSet • -addObject: • -removeObject: • -containsObject: • -anyObject

  6. NSIndexSet • -addIndex: • -removeIndex: • -containsIndex: • -enumerateIndexesUsingBlock: •

    -enumerateRangesUsingBlock: • -countOfIndexesInRange: (et al)
  7. Sets can be indexes for other collections • NSSet :

    NSDictionary :: NSIndexSet : NSArray • [dictionary keySet] • [NSIndexSet indexSetWithRange: • NSMakeRange(0, array.count)]
  8. NSSet theory • -intersectsSet: • -isSubsetOfSet: • -unionSet: • -minusSet:

    • -intersectSet:
  9. NSIndexSet theory • -containsIndexes: • -enumerateRangesUsingBlock: • -intersectsIndexesInRange: • -addIndexesInRange:

    • -removeIndexesInRange:
  10. NSCountedSet • -addObject: • -removeObject: • -countForObject: • -initWithArray:

  11. "An object can be put into the same pool several

    times, in which case it receives a release message for each time it was put into the pool."
  12. Let’s talk about ordered collections baby

  13. NSArray and NSOrderedSet • -objectAtIndex: • -indexOfObject: • -insertObject:atIndex: •

    -removeObjectAtIndex: • -exchangeObjectAtIndex:withObjectAtIndex:
  14. Ordered collections and NSIndexSet • -objectsAtIndexes: • -insertObjects:atIndexes: • -removeObjectsAtIndexes:

    • -moveObjectsAtIndexes:toIndex: • -shiftIndexesStartingAtIndex:by:
  15. Searching • -indexOfObject: • -indexOfObjectPassingTest: • -indexOfObjectAtIndexes:options:passingTest: • -indexOfObject:inSortedRange:objects:usingComparator:

  16. Filtering • -objectsPassingTest: • -keysOfEntriesPassingTest: • -indexesPassingTest: • -indexesOfObjectsPassingTest: •

    -indexesOfObjectsAtIndexes:options:passingTest:
  17. intermission

  18. Making sets from other collections • +orderedSetWithSet: • +orderedSetWithArray: •

    +setWithArray • [orderedSet set]
  19. Making arrays from sets • [orderedSet array] • -sortedArrayUsingDescriptors:

  20. NSSortDescriptor • +sortDescriptorWithKey:ascending: • +sortDescriptorWithKey:ascending:selector: • +sortDescriptorWithKey:ascending:comparator:

  21. Invocation • -makeObjectsPerformSelector: • -makeObjectsPerformSelectorWithObject:

  22. Concatenation • -componentsJoinedByString:

  23. NSCache look it up!

  24. degreesgame.com Kevin Conner @connerk