From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Using ARC

Using ARC

- [Instructor] One of those difficult things for even experienced developers to understand is Automatic Reference Counting, or ARC. It's how Swift manages and conserves memory automatically. Take a look at the exercise file. I have a playground in here that has project with two classes. One is a pizzaTopping, and one is a Pizza. Look at the PizzaTopping class. It has a string, another variable we'll talk about in a minute that references the Pizza, an init, and a deinit. The Pizza has a name, a variable that references toppings, an init, and a deinit. Now, deinit is a method that executes just before the class is deallocated. And we'll use it to see things disappear, because that's what we're trying to do here. If you go further down the code, you'll see I made a few toppings and pizzas on a do block. The do block will let us execute this in a way that it won't be global. And I'll show you why globals are a problem in a minute. Go ahead and run that code. And you'll see on the bottom…

Contents