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