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.

Preview
Close

Transcript from the "Cocoa Pods" Lesson

[00:00:00]
>> 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.

[00:00:22]
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.

[00:00:47]
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.

[00:01:08]
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.

[00:01:37]
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.

[00:02:00]
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.

[00:02:19]
>> 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.

[00:02:46]
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.

[00:03:08]
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

[00:03:35]
>> 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.

[00:04:01]
Okay?
>> 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.

[00:04:24]
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.

[00:04:47]
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?

[00:05:19]
>> 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.

[00:05:40]
>> 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.

[00:05:58]
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