Simpson TableView
Start course
1h 22m

This course delves into Object-Oriented Programming (OOP), covering its main components, and then putting these into practice by walking you through the creation of an app using OOP.

Learning Objectives

  • Learn about classes and how you can leverage them in your code.
  • Learn concepts such as Enum, Inheritance, and Access Levels
  • Understand how these can be used to build apps

Intended Audience

This course is intended for beginners who want to learn how to build apps using Swift.


To the most out of this course, you should have some basic understanding of programming and computer science in general.



Hi, within this lecture, we're going to display those Simpson models in our tableView. In fact, we're going to display only the name of those Simpson values, right?

We're going to display the other features in the details viewController. So, let's come over here, and rather than saying these dummy values, we're going to use the exact values. So, first of all, we have this homerArray in here. And I don't like that because we're going to need those homerArray values. So, I'm going to create homerArray in here, right? And the homerArray is not a good choice actually, we can call the SimpsonArray, or you can just call this mySimpsons, okay? And open the parentheses and this mySimpsons will have Simpson objects inside of this array. And we have to initialize this as an empty array, okay? So, don't forget to just add some parentheses over here, okay? Open close parentheses and this will go away.

So, rather than using homerArray, I'm going to append my model objects inside of this array. So, I can go over here and say mySimpsons. Okay, let me delete this, mySimpsons. So, what was it called? mySimpsons.append. And this is a SimpsonArray so it will ask me for a Simpson element and I'm going to add one by one. So, 'mySimpsons.append(homer)', 'mySimpsons.append(marge)', okay? So, let's do this step by step. Marge, Bart, and then let's go for Lisa. And then, lastly, 'mySimpsons.append(maggie)'. So, here we go, we have our array, right? And we can reach that array from anywhere in our class. So, I can go to other functions right now and call this mySimpsons array without hesitating. So, rather than saying, 'return 10', I can just go over and say, 'mySimpsons.count', right? I could have just said five but it doesn't make sense. I can add some more values later on. So, I'm going to go over here and close the series down and say, 'mySimpsons.count'. So again, this is okay. numberOfRowsInSection, we got it right. But, right now, we have to make sure that we display the name of the Simpsons inside of our tableView cell. So, I'm not going to say Homer Simpson in here, rather I'm going to go over and say mySimpsons. And for index, remember, we can just go for and say indexPath.row because IndexPath is given to us with inside that function, so you can just call and say (indexPath.row). But this won't do it because this will return us a Simpson object. And I cannot show a Simpson object in my cell because I need a string in here, right? So, rather than saying mySimpsons(indexPath.row), what will I say? So, this will give me a Simpson object, right? So, if I say Simpsonobject., it will display the name to me. So, I'm going to display the Simpsons' names in my cell.textLabel?.text. So, this is going to work right now because we are done with the setup. So, if you run this on your simulator, you will see the names of the Simpson objects. Here you go. We now see the Homer Simpson, Marge Simpson, Bart, Lisa, and Maggie. We have it all here. So, the next step will be to pass this information. When we click one of these objects and display that related models, related objects values inside of our details viewController. We're going to do that in the next lecture.

About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics