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

Collections in Swift

Collections in Swift

Talk at CocoaConf Chicago, March 2016

Avatar for Nate Cook

Nate Cook

March 31, 2016
Tweet

More Decks by Nate Cook

Other Decks in Programming

Transcript

  1. A sequence is a series of values we can access

    one at a time » 6'2", 5'7", 5'9", 5'4", 5'11" » 0xEF 0xBB 0xBF 0x4E 0x61 0x74 0x65 » 22, 27, 4, 8, 28, 14, ... » 0, 1, 2, 3, 4, 5, 6, 7, ...
  2. let numbers = [1, 2, 3, 4] for num in

    numbers { print(num) } ...is equivalent to: var gen = numbers.generate() while let num = gen.next() { print(num) }
  3. Iteration » contains(_:) » minimumElement() / maximumElement() » map(_:) /

    filter(_:) / reduce(_:combine:) » prefix(_:) / dropFirst(_:)
  4. Collections provide indexed subscript access to their elements » Arrays

    » String views (i.e., "Hi there".characters) » Sets » Dictionaries
  5. Indexed access to elements » Collections are sequences, too »

    prefixUpTo(_:), prefixThrough(_:), suffixFrom(_:) » subscript(Range<Index>) » count, isEmpty » indices