Check out a free preview of the full iOS App Development with Swift course

The "Cocoa Pods" Lesson is part of the full, iOS App Development with Swift course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano demonstrates utilizing an environment variable to inject variables from the OS. Student questions regarding why Alamofire was used and not CocoaPods and the benefits of using Alamofire are also covered in this segment.


Transcript from the "Cocoa Pods" Lesson

>> There is one more thing before they inform, that's the last section, that is pretty simple. That what if after hitting odd, I wanna go back. Okay? So I wanna go back I when I do this. Do you understand what I'm trying to do here? So if I hit add, I wanna go back.

That's typically the behavior because if not, you're still on macchiato. So I don't like that. So, to make it work, we're going to use, for the first time and the last time for today, another kind of environment variable, okay? Instead of environment object we are just going to call an environment without something else.

Okay, environment, like this. And we're going to, first I'm not in the right place so I'm sorry, I'm going to that again. So what we need to do, we need to go to details page. This is the one that we want and in details page, what we need is an environment variable.

It's called and a variable. And we are going to call this dismiss, okay? Just that dismiss. And okay, it says, something is missing here. Well, environment receives an argument. And we're going to use some special syntax here, that is called a path. So forward slash dot. And here we have a lot of things that we can read from the context, from the OS.

Okay? So the time zone, the calendar, the color scheme so you can know if you're in dark mode or not and there is a dismiss function. It's actually a function. So with this, you can kind of bring as a dependency, things from the west, the screen size, the current orientation, the current locale, so the language.

And this means, it's something that I can do then, after adding to the cart. It's a function actually. So I can call the function, okay? So it's a way to inject things from the US. So now if I hit add one, it goes back.
>> That's good, just real two quick ones.

>> Yeah.
>> Alamofire. One question is, is there a reason why you didn't use like a pot? Or what's the difference between adding-
>> Okay, so the question is around crockpots. So we use, for our dependency, for Alamofire, we use Swift dependencies. There is a package manager built in Xcode.

But that package manager didn't exist, a few years ago. So the community came with an idea. Similar to NPM, that is a community base, originally at least it was community based. So one of these solutions is called CocoaPods, okay? But it's not created by Apple and it's not integrated with Xcode.

But it's a solution and I could say probably the most used solution out there, for iOS developers, but because this wasn't available before, the Swift package manager was not available before. So you have CocoaPods, there is also another one called Carthage. Okay, so we use the one that we have Xcode, but if you wanna use CocoaPods and add the dependency using CocoaPods, it's okay, fine

>> And was there a better benefit of using Alamo fire versus the native HTTP kind?
>> Less code.
>> I see.
>> Yeah, Alamofire it's actually using the API from the west anyway. But it's less code for most of the things just was, like the Fetch API JavaScript, compare with the old XML, HTTP request, just to give you a web comparison.

>> One more question.
>> Yeah, sure.
>> Sorry. The In is still throwing me off, like crazy.
>> The In, yeah. So the In, let me see if I have one somewhere. No, here we have one in orders page. So the In were appears, no. This is going to manual page, here.

So every time you're creating, this is a closure. A closure is a function. The function can receive arguments, okay? And you need to name those arguments if you want. So to name those arguments, you use the In, before the In, you map the incoming arguments with names, with local variable names.

Names. Again look at this, in, if you know JavaScript, this is like in JavaScript, the example you have there. Like having a for each function that receives something, menu and as a second argument a function with category. Okay? So this category that you set here, is this category here but in this case, you put that in there, why?

>> This is the order of the Inconel, throws you off the sound like in, I mean it's the-
>> I mean what is weird, I know it's weird, I got used to it, but I know it's weird, is that the signature is actually after the calibrates. Because our functions in JavaScript also have this, but the name of the arguments goes before.

>> Right.
>> As a prefix. But here they are in the code book. And how do you separate your code from the name of your argument with the In expression?
>> Did they just make it probably quick kinda and-
>> By the way, Kotlin and other languages, they're using the same idea.

Not In, but it's kind of the same thing. They're also putting this inside the closure, inside the lambda expression. So it's kind of a mother and father.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now