From the course: iOS Development Tips

Unlock this course with a free trial

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

Dependency injection

Dependency injection

- [Instructor] Dependency injection has got to be one of the most annoying terms in all of programming. It describes something that is so blatantly obvious, we don't even know we're doing it. Let's look at what dependency injection is and what it is used for. If you download the example file, you'll find a playground. I have two classes here. We have the pizza class, uses the size class to get a size. Put another way, pizza has a dependency of size. I set initial values for height and width. So if you run this, this'll work fine just as it is, but right now it would only give me an area of 120. If I want to change the height or width, I have to make an initializer for size. So I would go into here and do an init and then do height double and then width, double. And then of course self dot height equals height and self dot width equals width. Okay, and you'll see that we get a missing arguments down here. So I can go…

Contents