English subtitles

← 04-16 Swift Session: Collections and Tuples

04-16 Swift Session: Collections and Tuples

Get Embed Code
1 Language

Showing Revision 2 created 04/08/2015 by Udacity Robot.

  1. Welcome to the Collection Swift session.
  2. We're going to ask you
    to do some reading about
  3. the Swift collection types.
  4. It's a really important topic, but we
    think you'll find it's pretty pleasant.
  5. There are only two collection types,
    arrays and dictionaries.
  6. They're both really clean,
    really easy to use.
  7. Let's start with the dictionary.
  8. There are two small wrinkles that we
    want to discuss before we read the books
  9. chapter on collections.
  10. Two short side topics.
  11. The first is the topic of tuples.
  12. The chapter that you'll read
    discusses this loop for
  13. iterating through a dictionary and
    printing out all the keys and values.
  14. Notice that for each iteration,
    we'll handle two values in parenthesis.
  15. We call these tuples.
  16. They're an interesting feature in Swift.
  17. Right now, UIKit doesn't make
    a lot of use of tuples, but
  18. reading up on them will help as
    you read the collections chapter.
  19. The second side topic worth
    reading up on is how to deal with
  20. NSDictionaries and NSArrays.
  21. These are the objective C collections
    classes used in UIKit libraries.
  22. In this example, I've created a UIView
    and I'm asking it for its subviews.
  23. We can ask for the count of the subviews
    and it's zero as we'd expect for
  24. a brand new view.
  25. But if you look at the documentation for
    the UIView class,
  26. you'll see that it's an NSArray.
  27. Since all of UIKit is written in
    objective C, it pays off to take a quick
  28. look at how Swift works with
    NSArrays and dictionaries.
  29. You'll find that this kind of
    thing comes up a lot in UIKit.
  30. We think you'll be pleased to see that
    the objective C collections integrate
  31. fairly seamlessly into Swift.
  32. So take a look at the reading list.
  33. It asks you to read
    a section on tuples first,
  34. then a chapter on Swift collections.
  35. And finally, a small section on using
    NSArrays and NSDictionaries in Swift.
  36. As always,
  37. make sure to take full advantage of the
    discussion forums as questions come up.