[MUSIC] All right, so let's go ahead and implement what we need for our collection view. So now, that we can get our current location we can show our Latin long on the me view controller, and in then neighbors view controller we can show our position on the map. And also use our stored current location to make a call to the server to ask for other users near me who share my hobby. Now we can make sure that our collection view that holds my hobbies. Actually works and looks good. So let's see how we do that. The first thing we need to do is tell our collection view how many sections will the collection view have. All right. So we have two different collection views in our application we have the available hobbies collection view, and we have the quote and quote my hobbies collection view. [SOUND] So I'm just going to put in the closing bracket to help get rid of the errors as we type so, doesn't look too confusing. Now, when the collection view asks for the number of sections or the number of rows or asks for how to configure the cell, it's well, inside of these Functions. We'll get past the collectionView that's asking for the information. So since we have two different types of collectionView, we want to inspect which collectionView is asking for the information. So if collectionView equals the hobbiesCollectionView, that's My Hobbies collectionView, then we'll return 1, because there will only be 1 section. And then we can say else the only other type of collection view in our application is the available obvious collection view, so we'll say Return availablehobbies.keys.count. Remember that availablehobbies is a dictionary with a string for a category of hobbies, and the value for that key is the list of hobbies for that category. So that's why we say return availablehobbies.keys gives us the list of keys. Which in our case means the list of categories. And then, we can know how many sections there would be, because we would make a section for each category. And I must have a little typo here or something. I have two curly braces, so let me get rid of one curly brace. There we go. All right. The next thing that we need to know is how many cells will be in each section? So, we can say collection view number of items in section, and again, we In collection views we refer to the object that the cell contains as an item. So the number of items in the section should be the same as the number of cells in the section, if that helps you visualise it. Again we want to look at which collection view Is requesting the information. So if it's the hobbies collection view, then we want to know about how many of my hobbies do I have. Now, my hobbies is in optional array, so it may be nil. We want to put in a guard statement, to say if my hobbies is nil. Then return zero, there won't be any cells in this section because I don't have any hobbies to display. But if that's not the case, then I can just say return my hobbies. Force unwrap it because we've already guarded it so we can force unwrap it alright and I can just say .count. So give me one cell for every hobby that I have in the my hobbies array if it's not nil. All right, otherwise if we are in the, not in the hobbies collection view then we must be in the available hobbies collection view. So we can just put else, now since we made the number of sections in collection view for available hobbies dynamic. Based on how many keys we would have if we had multiple sections. In our application we'll only have one, the technology category, so there will only be one section. But if you wanted to add more categories then putting this in an away is a hint to how that could be achieved. So I need to first, I need to make also the number of items in section dynamic in the same wave based on the category if I have multiple categories. So I say let key equals an array that's with the available hobbies keys array dot keys array. And now I want to take a look at this section that we're being asked about and get the corresponding key out of the keys array. So now you know what my key is. In other words, what my category is. And now, I can just go ahead and return the number of hobbies that are stored in the value for that key. So I can say return availableHobbies, the array of hobbies at the key that we just determined, and we'll just assume that it's not null so we force-unwrap it. And now we can ask for the count of the array of hobbies and that kind of worry. All right, now that the collection view knows how many sections and how many cells in each section it should have, we can finally configure how the cell itself should look like. So we can do that with the CollectionView cellForItemAtIndexPath function. We want to be careful about our memory. We don't have that many hobbies in our application, so we won't have to create that many cells. But theoretically we could have many, many, many, many hobbies and we would have to create a lot of cells which could eat up a lot of memory. Our cells are pretty simple but hypothetically making lots of cells can eat up a lot of memory. We don't want to do that, so we're going to use this collection view dequeue reusable cell with the identifier function. Now, this only works if we do two things. We have to set this identifier on our prototype and our storyboard. And we also have to make sure that the function here doesn't know what type of a UI collection view it will get. So we need to downcast it to the expected type which is our hobby collection view cell subclass that we wrote. So we can point to that little label inside of the cell and display the name of the hobby. So let's go do that now. I'm going to copy this reese identifier here, HobbycollectionViewCell and I just made that identifier the same as my Cell's class name, and that's a pretty helpful technique. So if I go to my main.storyboard, here is my collection view cell. I want to make sure I'm selecting the cell, not the label inside of the cell. And in the attributes inspector where it says collection reusable view identifier. I want to paste that identifier and spelling and capitalization counts. So be careful. And also I need to go over here and set the custom class event of that. Which will also be called hobby clutch view cell, so I need to go and create that hobby collection. You saw class very quickly. So I'll come over here and say plus, and new file, and [INAUDIBLE] called [INAUDIBLE] and this should be a sub class of UI collection view cell. And make sure again the language is swift so save it into the default location. We want to import ui kit and not framework because we're dealing with a ui, something something class so ui collection comes from ui kit. And if I go back now I want to point to this label inside of the cell that will actually display the name of the hobby. So I'll use my Assistant Editor up here. This overlapping circles button gives me my Assistant Editor. And if I select on the cell, sometimes it will go to the correct class, and sometimes it won't. If it doesn't, you can just select the file over from your files navigator, and drag the filename to this white bar on the top of your Assistant Editor. And when you let go, we'll see that class, we'll see that source file. So now, we can drag from, excuse me, Ctrl, hold down Ctrl on the keyboard, and drag from that label over to our hobby view cell class, and this will be called hobby label. And I can hit connect. And that's all that that class needs to do for us, is point to this label. So I can get out of my assistant editor, and we can go back to the hobby ShareView controller. All right, so now I've created the identifier. And the custom sub class for our UI collection. Now again we need to look at which collection view is asking how to configure its cell. And so, I will say- If collectionView == hobbiesCollectionView, then we'll configure this all one way. else, we must be in the available hobbiesCollectionView. And we'll configure the cell another way. So the hobbies collectionView should look at the myHobbies array and display the corresponding hobby for each cell. The first cell should show the 0th hobby in that array because arrays are zero bit indexed. The second cell in the collectionView should show the first hobby etc. This is represented by indexPath.item. So when we're working with these collection views, we want to look at the index path that's passed back to us in the Function. And then, look at either the section or the item to determine where in the we are and we want to grab the corresponding hobby. And in my hobbies array for the cell that's at the section 0, item 0, item 1, item 2, etc., so that we can fill out every cell in the collection view. So now that we've gotten the hobby, we can now just say So .hobbyLabel.text equls hobby. Oops, it should be lowercase hobby.hobbyName. All right, so now it's going to complain to us because our hobby class doesn't have a hobby name variable quite yet. So let's go put that there. If I go to my models.swift file, and I want to go to hobby, and I'll create a new variable called hobby name and it will be of type string. And we'll make it optional and we'll see why later on why it's optional. Okay, so we've silenced that error. And that's good. Now we can do the same thing for the other collection view in this else, which is the available hobbies collection view. The available hobbies collection view needs to look at the hobbies in the available hobbies array, makes sense right? So, we want to again do that dynamically based on what category we're looking at. Even though we know in our application there is only one category. But we'll say let key, which represents the category, equal the array containing the available hobbies, keys array. And then, we'll ask it for the IndexPath.section to get the section that our cell is in. Then, ask it for the list of arrays that are in that section. Then, for each cell that's in the section, we'll set the Hobby label to whatever the name of that Hobby is. So again I can go look for the hobby that is in that array of hobbies. And then I can say the same thing here. Cell dot hobby label dot text equals hobby dot hobby name. All right, finally remember this function has a return type of UICollectionView cell. So now, that we've configured the cell, we actually have to return the cell that we've configured. So we just say return cell. And that error at the bottom will go away because it was complaining we won't return anything, but now we have. [MUSIC]