Swift Cookbook: Swift 4.1 | DevTechie Interactive | Skillshare
Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
10 Lessons (4h 16m)
    • 1. Swift Basics

    • 2. Swift Basics Part 2

    • 3. Swift Basics Part 3

    • 4. Swift Strings

    • 5. Swift Arrays

    • 6. Swift Sets

    • 7. Swift Dictionaries

    • 8. Swift Loops / Control Flows

    • 9. Swift Conditionals

    • 10. Control Transfer Statement


About This Class

According to Apple Swift is a fantastic way to write software, whether it’s for phones, desktops, servers, or anything else that runs code. It’s a safe, fast, and interactive programming language that combines the best in modern language thinking with wisdom from the wider Apple engineering culture and the diverse contributions from its open-source community. The compiler is optimized for performance and the language is optimized for development, without compromising on either.

Swift is friendly to new programmers. It’s an industrial-quality programming language that’s as expressive and enjoyable as a scripting language. Writing Swift code in a playground lets you experiment with code and see the results immediately, without the overhead of building and running an app.

Swift defines away large classes of common programming errors by adopting modern programming patterns:

  • Variables are always initialized before use.

  • Array indices are checked for out-of-bounds errors.

  • Integers are checked for overflow.

  • Optionals ensure that nil values are handled explicitly.

  • Memory is managed automatically.

  • Error handling allows controlled recovery from unexpected failures.

Now with Server-side Swift you can become full-stack engineer in Swift language as well as develop apps for iOS, MacOS and TVOS. 

With Swift you can even write Tensorflow programs and make your way into Machine Learning world.

So lets get started today and learn all about swift and its fundamentals and get ready to change tomorrow. 


1. Swift Basics: another one. This is a new pope. Anti welcome to this in the video series on Ah, sift 4.1, the cookbook And what we're going to do, basically in this video series is you're gonna explore everything about ah Swift 4.1. That includes basically, not only the changes that came in, so 4.1, but, uh, starting from scratch. So if you are new to programming Swift then ah, discourses for you. If you have been using surfed, basically sift older origins like three or four discourses for us all and where you can actually learn about, um, Thea, Any changes? And ah, a new FBI things, stuff like that. Okay, Now, before we jump into the coat, I want to actually ah, express something assumptions that I'm making about to you. So one of the thing that I'm one of the assumption that I'm making it, you already know some sort of programming. So you have some sort of programming background where you probably know javascript or, you know, um, basically any other language other than self Or let's say if you don't already know served , okay, but you should have, like, some knowledge of programming so we can actually talk about stuff without explaining what variables are or what? Why we do loops and in conditional statements that stuff like that. Okay with that. How clear? Uh, let's ah, talk about the minimal requirements so you can basically ah, have a Mac and ah ah x code installed on that, uh, which is perfect. If you don't, Then you can actually google sift online editors and follow along for all the examples. And there are opens off the online editors that currently support the latest not only the latest version, but he can actually switch between different versions off so you can use those, Um, but it's it's actually best if you have like Xcor because, um, in the future off course is I'm actually gonna ah, start are basically expanding upon this series and ah, start creating some of the, uh, some of the previous series is on how to basically make IOS, perhaps, and ah Hotpoint of syriza about our different iris frameworks and how to use them. Okay, Um all right, so with that in mind, let's get ah into it right now. So first thing that the way I want it basically started. Um, have already opened X coat and ah have created a new playground. So if you go file new playground, uh, you can actually jump into this this screen, but I have selected a blank template that had, ah, import statement and everything, but have were cleared out everything. And on the other thing that I've done is I've actually So let me make this a little bit, okay, A small And I've actually, if you click on this area right here have changed this to manual execution or mental run because, um, I would actually like my code. And when I'm ready to run, then I'm gonna actually I want to press the execute button. What happens in the other case? It sometimes searches trying to follow you, and it tries to execute prematurely and gets stuck and then get and then gets crashed. So that's actually one of the book that I found on ex courtside. And this is the best way to do with this so we don't actually end up crashing and restarting in the middle out of the videos. Okay? So All right. So let's get started first. I want to talk about, um, constants. So constants are ah, labels are basically Yeah, they're sort of Abel's. And, uh, basically, what they are is Ah ah. They are just a pre defined value that he have created That you know that you're not going to change. There is immutable in the way you create constant in, um, served is using Let keyword. Okay, so let's say if you have Max number off Loggins allowing attempts, for example, I need to find it to 10. Now, this this really well right here. You can use it throughout your program. And whenever you need to change it, you just change it at one place where you have initialize it and it's gonna basically replicate, or it's gonna represent that value for, like, you know, wherever being used. Now constants are immutable. Once, once again, eso you cannot actually just go and say maximum number off log in times is equal to three. That is not going to work for that. We use something called an actual variable. So it's actually called valuable, and we created using were keyword. And unless they we have current logging attempts, okay. And let's see have three our four. Okay, So, uh, or did you start with zero? Now, variables are a mutable and you change them over time. So let's say you had a form. Let's imagine you had a form along inform and a users trying to log in if they if they logging on and fail. Then we increment the current logging attempts on Now we keep implementing and we do a check thing. If the maximum log in attempts are become more than 10 then locked this account. So your maximum number of logging their terms is a constant variable because, like that is a value that's gonna be that's gone. Remained constant throughout the execution off your program. But your current log in attempts is your run book, basically, is keeping a track on how many times user a user has actually how field before completing, basically or successfully locking or basically failing in locking himself out. Let's hope that is clear now. One of the ways you can declare multiple constants are multiple variables is using a single line form so you can say, like single to be taking a single line. Um, Babel declaration is ah, basically using wire and you say exit tickle to the 0.0, for example. Bicycle to zero and C is CO two's. Okay, so that's how you can actually declare an X Y and Z values are going to be ah, are going to be initialized with 000 Okay, let's run this so we can see, like, you know, what we have says it gets here how we have Mexican over a plug in the time stand current log incense, current value zero If you actually go and say current influences physical to current longer attempts Bless one the Valley is going to be really is going to change. Basically 21 on this line. So now the current value of current log in terms that Okay, so that's how you actually change variable. Okay, now the song. What type of mutation? So type annotation is basically type and notations. Okay, type conversations are basically, um, very off declaring what type of variable it is. So ah, check this example out one more time, so maximum number flowing in attempts. It's equal to 10 now. In this case, you did not have to specify what the type after the able it's going to be. And if you often if you press on option button on your keyboard and hit Ah, and and basically mouse over a you're able name and when the question mark appears, just click. It's going to show you that maximum number off long in attempts is integer type. Now, we did not tell it that basically, this is an in type. Ah, Compiler actually automatically inferred that. So by looking at the value that is on the other side of the equal sign, it actually inferred that hate. This number is an integer So what? My eye. What this person won't want me to do, basically, is to create this maybe people as and into Jenner. Now, there are some cases where are type influencing does not work the way you expected to work . So, for example, let's say like you know you off. If you if you don't want to define you can just for Iraq's for spring and everything, so you can say welcome message, for example and you say hello. Okay, if you check its type by again holding option key and uh, clicking on thieve able name, you're gonna notice that is a string type now you can go and very will create liking our protocol. Semicolon are set up for the colon and then say it's a string type. Well, it's not going to change the fact that it's actually already inferred that, but you can be explicit about it now. The problem, it comes when you actually use fractional values. So, for example, if you say, uh, pie Okay. And he said three treat pint 0.141 for example. Okay, Now, can you guess what the type off by would be in this case? Um, if you guessed that is going to be a float type because floated one of the data type or data structure in served, um, that is actually true. But in this case, it's gonna be double. Why? Because double it is optimized at the compiler level. Okay, so what happens is when Whenever comm policies a fractional value, it thinks that it's actually better to convert it and or treated as, ah, a double value or stays a floater out. You okay? Now, I know in some cases, basically, in a lot of cases, even in Iowa s frameworks yourself, there are places there. It only accepts afloat, or it only accept certain kind of float like city floating stuff. Okay, now, when it come to that point, that's where you can actually have to do Thai politicians. They say it's going to be a float. Well, okay. And now, if you often click on the on the table, you gonna know that that's actually changing to float. Okay, so I hope the type of rotation is clear. There is one more way you can actually define type of mutation. So, um, you can say so. For example, single line type invitation. And you can say read Green. Who, for example? So if you say that and if you, whatever, you'll notice that everything is defined to a double value, okay? Or if he's saying float, Adam and house ever in option click, you're not. Everything has changed to float. All right, cool. So let's talk about ah felt the naming conventions. So, uh, naming you are Babel's okay in In Constant, it's implicit that we're talking about labels and constants like, you know what? These are just have able to evolve none up to three. Okay, So constants in variables can contain almost any character even the unique at a Unicode character. So let's say if you are say let and if you hold if you click If you hold command control and hit space, it's basically going to open emoji window, OK? And if he says for dark here, we're gonna find a dog. Let's pick this one. And if I say this is a down all right And ah, now, if I basically run this, you notice that have the dog emoji value is actually a dog. So what that means is, basically, you can have literally anything for your for your naming except a few rules. Rules like you know that you need to follow is white space. Uh, it's not love. Okay, um and, uh, so, uh, yeah, so basically variable names cannot contain Ah, Whitespace. So, for example, you cannot say let This is my where the ball name. Okay. It's not love. Right? Ah. Now, starting with mathematical symbols, for example, this is not allowed. All right, so that's that's another one. So, uh, coming that end names starting with number are not allowed. Okay. Um all right. Next other. Some private use you thinks like you have for example, he cannot create your available with name variable. That's not love, because that's a reserved keyword. So reserved key word Babel names are not allowed. Okay, so this is not allowed. All right? Next that they you gonna have, like, you know, of able name. Like like this. Okay, so this is not a lot. Why? Because he cannot start your label name with a special character. Now, um, I think, let's see if this is actually now. Yeah. So special characters. I'm not some languages actually do allow you to use, like, dollar symbols and stuff like that. Okay. How? All right, so but out. Okay, so one more thing I need to clear. Okay. Uh, first, this funny down names starting with special characters are not loud. Okay, now, it does not mean that basically, when we talked about the having the numbers, it doesn't mean that you cannot have number in your variable, so you can have you can have a big Babel name like this. You can have, like, let Ah, a new one. Okay. And, uh, like, for example, this you can totally have that. I mean, that's perfectly valid. Ah, and there's no issue whatsoever for this. Okay, So, uh so, yeah. So these air some of the some things I thought the naming conventions that do you need to follow basically, for your for the year. Babel names. Okay. And say this is allowed. So if it is allowed, OK. All right. Um, so, uh, now you can change the value off. Ah, an existing variable to another value with only compatible types. Now what does that? So that's EU creative able called welcome message. We already have that created. So that's great. Something so welcome. Okay. And he say hello now the type of your string type of off your able it's string. So I say, if I option click on this, I'm gonna know this a strict. So if I try to say, welcome in sick, old one, that is not going to work and it's gonna basically throw an error, it's a fine timer basically saying that you cannot have in teacher assigned to a strength I because it's type is already defined. So you can on lee a sign or change values of existing variables with the compatible type. So you can have, like, welcome is equal. Do Hello, sir. Left. Okay, so that is actually perfectly valid, as you can see here. All right, so that's type it out here. Um, so compare Diboll. Hey, uh, comb, pack TiVo type. Okay. All right. Okay. It's great. A a bit of a room here. All right. And then we're gonna go, uh, now, up now, because of you cannot change constants. Basically, after they're being said, uh, you can basically like, you know, you see, this rule literally does not apply to let this rulers Onley related to bring about right. That's not what Printing so printing and deep up console. All right, this is your debug council area, and, uh, let's see, you want to put some log messages while you're working on nap, for example, you wanna print which you are ill? You are Ah, AP is going to it. Or which your l your app has resolved to after generating that. Like you Now from some complex formula or something. Making think that, but like, you know, you want a friend something and you want to see it on the Facebook Council. How would you do that? Well, it's very simple. You just say print right. And as you can see, there are few or lords off print how fast it takes simply, like any kind off any kind of parameter. That's what any is. And then we have, like, you know, text output stream. So ripe the textural representation to the given output stream. Like So, for example, this time we're actually writing on the console log window. But you can actually override that to have, like, you know, be written something else. All right? And then another overload is basically out. Whatever your print statement is, a separator where the value is going to get separated, like, you know, based on explicit space. And Terminator is basically turn it line with new line symbol or any of the symbol that you have. Okay. And, uh, the 4th 1 is basically, um, just like, you know, an overload with text are extreme. Now, um, this is Ah. I mean, as you could be like, this is basically writes that actually information given item suitable for debugging into standard output, which is there's murder. So your screen right here, but you really don't don't have to use it. I mean, are you a print out Also, people actually use print straight out the box. And it's not that it has never create her problem for me. So I use I use print. You can use development, that's all. Okay. After you. Right. So let's print something so we can print our welcome. Oh, are we can print. Welcome The message are desperate Walk, actually. Well, come very both. So really available because it has. Hello. Stuff that. So let's plate. There you go. So first line it actually are printed. Welcome message. And second line actually printed a welcome out variable which is actually eventually resolved to Hello. Soft in. Excellent mark. Okay. All right. So, um, what can we What can we Basically what else can we do? We can do Ah, string interpolation. So, for example Ah, you wanna basically let's say, you know, say ok, bye. So let's suit that that example. So, uh, string inter relation and you can say print and, uh, difficult in here, you can say value off pie if and now you want to basically use a variable here. So all you needed it. Uh, but backslash open record, close packed. And between these practice eyes, your area where you contract up your cold, so I'm gonna say bye. And if I execute this is gonna actually print that variables value along with string that we have brought it and this is called a string interpolation. Now we've been using the next thing we've been using quite a lot, but we haven't talked about it. A single line comments. So they say, is a single line comment and a safe You wanna put multi line you can put between these two so far slash star starboard's star forward slash and anything Your type. Um, anything. You dive here with model T PO lines on it. They'll also be considered. Has government. Okay, so this is another for off common think multilane comment. Um, all right, stock, But Simic ALS so semi coolers. If you noticed in lot off other languages even adopted to see ah, you always have thing going. Terminating your line now and get a served the new land character. Um, basically the return or enter interprets that that that line is complete, just like bite down. Okay, um but you can have seem Collins and Sophie will not complain about it, so I can have like, you know, let Cat is equal to And if I put cat catting was you here? Example. Hi. Um, it's put, um has a string. All right. Um, here, um I can I can absolutely have a space Santa Claus like that. And sift wouldn't have any issue whatsoever for this. Say it just worse. And it shows that value just fine. OK, so, um now Oh, it doesn't matter. I mean, you can get it if you're heavy Chill. You know how to use, but you have to You have to have it if you have multiple line statements basically written in a single line. So I say you wanted to for some reason, you artist safe space. And you are say let Cat is equal to emoji cap and then you wanna print cat. Okay, so in this case, you cannot have this way. If I do that Ah, the the compiler is going to basically complaint, and it will suggest what could be the solution. So if you just accept that it's gonna basically place, um, it's in Golan right after the initialization. Okay? And if I execute now, you're gonna notice we actually are printing cat. So that is how, and you can actually ham cynical on if left a thought. Okay, Now let's talk about intuition. Indeed. Here's so indigenous are like basically whole numbers with no fractional components. So you can have, like, 42 or negative 23. Those are integers now sift provide Signed in Tages and anti Indigenous, like in eight page 16 32 bit and 60 form it forms. And these intentions follow the naming convention similar to what? C language stuff. So in eight bit unsigned and teacher, it's gonna be you in eight or a 32 bit signed in. Teacher is going to be into 32. So without you, okay and a teachers have her up around and lower bond already defined. So let's say if you have, like if you find out what the minimum value off Internet seeking same in hell. All right, hint. Man foul is equal to int dot men, okay? And like, so you can actually find the max. So you can say into Maxwell is you call to into that, Max, I se fi execute right now. Ah, you gonna notice that it's going to give you the minimum and the maximum value for a signing teacher. Okay. All right. Um, now, um, a software 14 points. So float, float. Floating point numbers. So floating by numbers are basically fractional components now, such as 3.14 every years. Last time. 0.1 or negative. 22. 73. 15. Now, floating point types can represent a much wider range fairly than interior types and basically taken store numbers that are much larger or smaller than what you can have. Um, within either signed or unsigned integer. I just just said that, um, now double is a represents. A 64 bit floating point number and float represents a 32 bit floating point number. Okay, um, and the way you actually just create it is, uh oh. When you just say what are by, for example, new by, and you give it a type. So you say float. Hi. And here you can see float 32. A slow friend full of 64 is double. All right. And this is floated. He's an extended precision Foreign point Valley phone. A user. Right. So we're gonna stick to float, and we can say 2.4 and that it's going to be a float type for you. No. Um, all right. I think I feel like, you know, this is probably a good point to start to stop. And what we can do is, uh, from the next video, we're going to start talking about, like, you know, we will talk a little bit about, like, a decimal binary in October. And decimal numbers are basically how to create them. And ah, one. So we have those who get out we're gonna see, like, you know, how we can have been convert one type to the another. Okay. And, uh, and, like, you know, we're gonna see basically convergent from double to float, interior to float, float to interior and less stuff. Um, OK, so I hope you guys enjoyed this first video. And, uh um, let's keep going and get through the basics first house so we can start discussing. Felt the advanced topics like classes, urinary expert locals, um, the and stuff like that. I So you guys go to studio. I will see you guys in next video with mawr apart. Sift. Okay. Thank you. 2. Swift Basics Part 2: right. Hello and work, Mac. And into video how we are going to be talking about some hard numeric liberals. Like, how can we write decimal binary octo in the Hexi decimal numbers in slipped. So let's get started, eh? So let's create a decimal. And and 17 I was creating a binary so that binary hint. So see, you will be here. How represents the binary? Ah, tradition. So we can said 100 you know, fun. Hi. Ah, that is 17 in binary. There you go. And then he can have Octel hint and that if that's hero Oh, for example 21. Okay. And that is actually 17. Right? So okay. And then basically hex and is equal to, um the O X 11 for example. And that's actually decimal. Conversion is 17 for that room assault. Okay, so those are This is how you basically create our different types off new work in numerical systems. Eso basically can have, like, that's more binary, octo, extra small, for example. Now, what you can do is for decimal numbers. With the exponents off e XP, the base number is multiplied by 10 PX be. And this is how are basically, um, you can you can write it. So I say you had a a number, and he conveyed to that, for example, that exponents double is equal to 1.2 18 e one. Okay. And if I execute that you gonna notice it's basically called 0.18. That's what I hover, too. Okay. And, uh, and that's actually one way. And you can actually have even have hexes ehsmoh exponents as All right. Um and so say that hicks double is equal to feel x c dot three piece o right. If I execute that I stayed out. What do we have, co 0.20? Well, 12.18 85. So, uh, if you have, like you sound five. That's actually going to be exactly same values. There you go. Okay. All right. Let's talk about how conversions. So let's say if you want to convert some value to indigent, so as say you had, um I say result has available, and ah, you would say, uh, basically int Morgan off by that we have created Okay, so if I execute this right now, you gonna see, Basically, it has converted. It has given us the value just three off by and pie is 3.14 OK, so that's how you actually convert any doors for double float or any other day restrictions on takeoff. All right. And let's talk about type Elise. So type releases are basically alternate names for existing types, and you can actually defined I previous. Is that because it helps you like, you know, if it helps you? Ah, getting on like, you know. So the, um it's refusing in. Then all that stuff, for example, he can say, Ah, already a sampling and all the sampling that men are already assembling dot um Max and basically driver from it. So, for example, you can say type alias okay, And you can provide the type of them. So let's say I provide audio sample and I would say you and 16 now, whatever I need actually, you in 16. I don't have to call it sweet 16. But I would say actually, Max are mean. Hamp Ah, it's equal to audio. Sample that man for example. Okay, so that extralegal So this this our example right here. Department eventually calls you into 16 Darkman, and it gives us are really back. Okay. All right. So next. Ah, my state of type is, um, basically Boolean and Polian is a sort of like a logical, um, did logical type. And because it's actually it can only be true or false, And I suffer writes a 1,000,000,000 constant. Ah, but bullion consents like are true and false values. So So let's say you can say it. Flag flak, this code, for example. True. And, um, it new flag is equal to false and that we have, like, you know, the other complete is giving us the valleys. And these are our boolean values. So how can you basically going to say if so, I say I say if flag this code uh, Brent Hello? Execute this. Oh, yeah. Okay, so if this is true, then it's gonna basically ah, and of the loop. And, uh and ah, Then it's gonna print that now, this is actually an example of control. So if else, um and, uh, basically, ah, sell a stock. But if else now so and so if you want, like, you know, if you want to branch out your decisions based on certain conditions, you can actually use control statements like if an else basically to dry what you want. And if your condition satisfies, then you can say, like, you know, execute this block off court. And if it doesn't satisfy than you can say, execute this block, of course. Ah, that where you can actually create Sort of like a control switch. So intent is are you created? Basically, you created with if the conditional check. So here we're saying, flag this coat, which essentially means flag, this code is equal, equal, true. And if it is true, then print a message and exit on. If it Now, let's say if it was not true, then it goes into the else sacred part. Read in, Say, you can do anything like this. This would never show up. Like so. All right, so this is what the control our segments are. Now, let's talk about our pupils are so triples our group off multiple rallies in a single component value, so the value within tipple can be off any type, and you really have to have same type for each Well they can have. They can be like a mixed type. So, uh, they say Tibbles. And I would say that STD B for four enter a severe creating an era gold dictionary of something and then we can say is equal to you. Can have, like, 44 and you can have, like, you know, the message is also not found. And, uh, I say if you are print and this incompetent STP that was here, so because we haven't named these eyes gonna basically refer to them as a zero in one. Um, and, you know, we're just gonna take a look like, you know how you can name these, but, um, you could say scdp 0.1. Okay? And if I execute this right now, you gonna notice it's basically gonna say for four, not phone. Okay, Now they say you say, like, you know, air code here, and, uh, you say message and, uh, message. So instead of referring to like, you know, you're on one, it's actually going to show you the actual names off their So you can say I doubt a message . Okay, execute that, and it's going to show up right here the same as before. Okay, so how so? Those are your two balls, and I can basically, um, received these values. So, for example, let's say if he hadn't had, like, you know, named these And if you want, actually, if we received this as a return from a function we can actually receive it in a tipple is also because they let Oh, God. Sorry. Uh, let, uh, great result, Um, to bill, it's equal to STD Pierre coat and out. You can actually, instead of that, you can say you are Oh, my He are msg example. And if I print, we are. And if I print he are MST, I'm gonna basically be able to extract out the information again. A different format. All right, so I hope that it's Ah, it's a bit clear. Now, um, let's talk about, like, you know, one of the topic that was entities in Swift, and it's being quite popular, and it's called optionals. So are even these optionals in situations where a value is absent, all right, in an r still represent two possibilities. Either there is a value and even basically unwrap that value and X and and extracted out, or there is no value at all. Okay, Now, um, you mean Lee create, like any type as optional and 50 perfectly a lot stacked. So, for example Ah, you can say like server. Think of a server response code is an optional type optional into what? It seems size. That's for four. Now, if I try to Prentice server response. Good. Um, I'm gonna get optional for four. OK, He had become in these other prints lines. Go quick. All right, I guess, uh, yeah, he's the last ones. Okay, so, um, go. We are also printing fewer things here. We predict this and somewhere we have printing our cat right there. All right, so safe and execute a little time. Um, As you can see, it's basically reading it as optional for four. And reason is because we actually created it as an optional. Now we have perfect. This is perfectly valid. If you say server responsibilities equal to know. And then if you try to print the same thing over a came we're gonna get now. All right? So that is for Freakley ballot and perfectly valid and allowed to basically signed something. Do you know now you cannot assign mill to non optional constant of Grable's if a constant invariable needs to be needs to work with absent absence of values. Then you have to declare them as optional valleys. Alright, Hope that is, um, eyes are clear now, in order to remove this optional thing. How we can do is you can actually force unwrap hip. And, ah, if you would like, you know, this explanation market actually says, like, force and wrap and foursome and wrap means I know that this value, it's never gonna be nil at this point. So please execute this on, and I can guarantee that there's always gonna be a value here now if we do for some rap here and, uh, try to, um basically right, we're going to get a fatal error because, um, because we're trying to unwrap on expectedly find Neil while unwrapping an optional value. So that's what happened. If you try to force unwrap something which is ah, like, you know, um, you cannot actually do that, so I mean air, your program crashes. Now, what are the ways actually to to this safely? So, for safe unwrapping, he can use a flett so you can say if let ah, yes, code, it's equal to server response code. And if it is, um, present Ah, print. Ah, the breath code, which is already unwrapped for you Now safely. Els, he say no. El you. Huh? Server response code is now, for example, if I execute right now, you noticed this Kind of basically going to the else block and say so responsible is now because we actually liken What did it do now? Okay, um, now there's ah thing called Ah um optional off. It'll binding. An optional binding is to find out whether an optional value contains something or not. Okay. And, ah, just like if statement like we are being really insistence called the this is called artful binding. Ah ah, y loop supports. Same thing is on. Okay, now, there is another way to, um, unwrap the values. And basically, that is guard. And it's basically guard. Let for example, uh, code is equal to server fast code else. You can say print Prentice. I hear and return now difference between if let and ah, because it's like, you know, there's no function here. We're just gonna say, um well, I don't think it's because it's gonna actually so we gotta throw fatal air. So we're bus scored his now. Okay. Um no. Confined to an error. Okay, so, um basically say, like, you know, because it's talking about it. Just great a function. And don't everybody if you don't know what functions are we gonna talk about, Like, infections in entirely new video. So we'll just just go from there. Sample funk, for example. And I can have, like, you know, guard that basically and and return from here. Now the difference between if let and guard it if if lap when you're you're optional is unwrapped, basically in the value is now assigned into Resco. It does not retain that value outside of this block. So read Scored s a Mr Stock ends it, May it It basically disappears on that. Value is gone now. Guard lead, actually. So step problem. So once you have resolved, he can actually use rez. Good for wrestled. You're following code within that, but in that same block. So I say, if Aiken, as you can see, I'm actually outside the car That but I can still say rez code. And if I execute basically gonna or perfectly fine. Um, when we called the example function. There you go. So it's basically printing the reason for, like, you know, that the service particle is actually now. All right. Um, so I guess, Ah, this actually another good stopping point. So less Let's stop here. And, uh, in the next video, we're going to talk about air handling, and basically, we gonna say, How can how can we basically, like, work with operated? Spike? You know, basically used tertiary, uh, our turn. Every operator for conditional czar, like, you know, have, like, you know, assignments and mathematical operations. Like, adds a practice multiple division. All those things. How can we do that in served? Okay, So I hope you guys got this video, and I will see you guys in extra help thinking. 3. Swift Basics Part 3: Hi. How long? Welcome back and Internet video how we are going to be talking about ever handling, So let's get started. So I'm gonna basically come in this error handling, and this is by no meu full. Um, full coverage off air handling. Basically, we're gonna ah, have Ah, hole. Like, a complete dedication in session for showing, like, you know, different aspects of hair handling. But I just want to give you, like, you know, a little preview off, Like, you know how they're handling basically works inside Swift. And this is just Ah, you know, uh uh, testing the water. Ah, and nothing more than that. And we're gonna cover in full detail in live videos. Okay, so let's get right on it. I know, like there are a few things that have did a minute are you are. So if you are not familiar, but those now, don't worry about it. We're gonna cover those in detail, So just just follow along and bear with me for a second. I just want to show you how the other handling works a real quick. Okay, So I'm gonna create an enema first and listen, um, let's say we create simple error, okay. And Adam is, like, you know, basically a It's sort of like a function. It sounds like a pretty find properties and different values in you can actually, uh, do a lot of things with Denham's, and we're gonna talk all all those a lot of things are. And I know I'm actually talking a lot of, like, you know, ah, promises here that we're going to do this and that. But I promise you, when you get there, you're gonna understand because there's a whole lot into it, then just looking at a simple example. So I just I just want to show you, like in our air handling work. So there are a few things that I want to show year, so don't worry about it like, you know, if you don't know that, OK, so, you know, we created simple in, um, a simple error, and that inherits from error. Okay, um, then we say that we have three cases. One is valid selection. Second cases in Balad operation, for example, and these can be anything out off stock. Okay, Now, um, unless you had a function, let's, uh my funk and uh, it throws an error. We know that he's gonna throw an error. If something bad happens, that's gonna throw another. Okay, so this is their begin. Say when? When he's for another, we're gonna call, like, you know, they say it throws sample at our dot invalid operation that are okay, so we call it we re tell it to throw when it sees an environment operation. Right now, this is there if you actually want to catch this error and una gracefully handled this. Basically, what do what do I mean by gracefully? Handling is basically not crashing your app, but showing your exert a friendly alert, saying, Hey, something bad happened and this is what the reason is, and we're actually working on it. And basically, take that, um, take what happened. All the colts second everything and put it in a loving system and then and then work from there, basically to investigate. So let's say you wanna handle the center. So what you do is he's simply saying, do okay and to try basically and you want to try it? The function that actually throws the error. Okay, so you say, try my funk right and you call it here now, if dysfunction was just a regular function without throwing any error, just doing its own work and there's no issue with it, it would simply execute this and execute the next line of code. Right? But if it is an era bronze function, then it's gonna actually try another, and that's they're gonna catch it and against the catch. And we have a print here dot so there is no localized description. So I think a rash begin, or we can simply say hair was thrown. Okay. So again, unless executed without any issue. So I'm just gonna print no issues here. And if I execute this, it's gonna print no issues here. It's not even going to go inside. Just print statement. Okay, Now, let's they, uh we haven't issue here, and we throw that invalid operation. Basically, the lime that is going to get executed is distant era rust, as you can see here. All right, because we are function true inner, and we caught that right at the moment. We showed a proper message to the user, and we actually loved it. So in this case, like we're doing both things in the same line. But again, this is just a sample to show you how do try and catch works in, sir? Okay, cool. So let's move forward. I started over a little bit detail on, like you know how they're handling works and, ah, let's talk about some of the basic operators operators and served Okay, So an operator is basically a symbol or a phrase that he used to check change or combined values. For example, if you want. If you use plus operator, that means adding two numbers. Or you can have a logical end, basically combining two Boolean values if you're checking for some kind off some kind of condition condition. So let's say, for example, you had a people I and you say, um, one blessed to. And if you print I, it's basically going to add these two. Well, you then show you the result. Now, this plus is an operator right now. Another example is to say, if we say I equally called three and type off, I is equal equal int. Then go here. You print for example. Okay. So unless he um I think type off ISS to find them teacher will be. That's you. What type of returns? So I see it's a print type off for transit into so I it knowing, um, you just say I is less than to right? So there two conditions were checking. Here. We're checking Icicle Drew three, which is and I is less than two. And this end operator is an operator, basically, just combining to bullion values and evaluating this whole this whole equation to see if the satisfies the condition or not. If it does, then print something. Okay, so it's gonna print. Well, um, I Is it equal equal three. It is less them to hi. Equally go he and it's That's an equal to to All right. I don't understand why it's not going to the next life. So you strange? That's how you get a straight health pranked. Nothing is good. Let's see if it goes in, Huh? For some reason, it's going in the I could see. Okay. Always good. I I'll get so and I Oh, course. Ice cream isn't too. I don't know, something happened. Well, obviously I three is not gonna be less than do because the highest three, which is why it was. Actually, this condition was failing, and that's why I was not going in that in that block. Now it is going on the block. I don't know. What was it? What was I thinking? But But anyways, yeah, this is the end operation. Hi. 1000. I bet. Okay. So, uh, less plastic. Look at another way off another operator. So operators can be a unity basically, like, you know, just having one. One simple operator with single target. Let's say if we say I think they say, like, you know, a r I a equal to, um let's say we create a available, you know, call it may be a Okay. And, uh, this is false. I and recreate a very will be with, ah, equal to not a So this exclamation mark is a not like, you know, it's opposite off what a is. So what we're saying is, whatever a value, this just flip it. So it's false than turn it into two. All right, so if I execute this right now, are you gonna notice that a its faults and B, it's true. Okay? And this is an example off. Ah, you know, Ari operator, Because There's only 11 target or one opera, and it's actually working on okay now, Uh, plus is an example binary operation because there are two operations involved. So you have one and you have to. So there are two values that are involved, and it it operates on these two. That's why says it's it's an example off a binary operator, I 3rd 1 is turn every operator and dissonance is very useful. A lot of situations. And I say if if I would create a r c is equal to out they be, um, equal, equal, true. So if B is true, then question mark. Okay, so, question mark, I would say, Ah, a fine three to see otherwise assigned to to see. Okay, so this example off paternity operator because they're three operations involved. So this is one. So this is the condition that it checks for, and these are after right after a question mark is the truth. Well, so if this condition evaluates to true, then this is what's going to get assigned. And if this condition evaluates to false, then this is going to get a sign. So question mark is, ah, a question combining question. Mark and Colon. Actually, this whole a question is, um, a turn ary operation. Okay, so this is a turn. Every operator, it's called basically a printer. Neri conditional operator. Um Okay, so this is turn Eri conditional operator. Ok, hope, hope that is the That's how clear. But we're gonna PLC like, you know, how are you going to use this when, um in I think some of the project in one of the course I'll actually show you when we start creating actual IRA saps, we're going to see, like how, uh can use salt ease. And you're gonna see all like, you know, all these things that you're learning in in a in a practical in real world by creating your own naps. Okay, Um, so all right. Back to back to work, Vera. We're exploring the the operators. Um, now, what else can you do so you can do addition using? Plus, um, operator, you can subtract using minus. You can multiply using basically star our home replication and division is followed slash. All right, then. Plus s. So there is a single operator overloading and operator were loading Is basically giving your operator and extra meaning, And you can create some functions to old load your operator. But pregnant Will. String has overloaded plus value. So let's say if I had a string welcome MST, for example. Okay. And if I would say hello, Um hello, plus wound. Okay. Now, in this case, what's gonna happen is is going to combine these two? It's not gonna add the's too, because, uh, well, no one knows how to add two strings, like low in hello and world. Okay, left. If these are numbers, we wouldn't actually, that would have been a different thing, because that have been in an interview question. Like, you know, he have to strength. How would you actually, um how do you add them? But we're not in there. Okay? So if I actually execute this right now, are you going to see that welcome message is going to be hello world. Okay, So basically, plus is overloaded and string to concoct, innate to values given. Do it all right. Now, there's another thing that's called remainder operator or modelo operator, and basically ah, modular operator is something that he used. For example, if you want to check even odd. So he checked the remainder off the off the equations. For example, this evening. Check check for like, you know, a value. A number is a is even or are. So I'm gonna months again going to get ahead of myself and create something that we haven't covered yet. But I guess you should be OK with that. So if I say for I in zero to 10 so what this meat is create a for loop with very well I and run it from zero up until 10. Certain is not inclusive. Ah, 10 10 is inclusive. But if I would say a less than then 10 is not inclusive. Okay? So if I If I do, if I want to check when I see an even number I should print even at the why should print are. And this is how it can do it with you remained a robbery. So I have to say, if I is, I'm on to equal you call zero. That means it's an even number. So say even number I Who else I would say print odd number high. Ok, so if I run it right now, you notice that we print, even a nod, and, ah, while sexually waiting and thinking. Um, OK, there we go. All right. Okay. So zero is even, um, because if you Mark, if you device something by zero, actually get zero one. It's odd because one divided by two is one which is not equal to zero. So remainder becomes one, and it goes to odd to certitude of To divide by two is one is basically zero. So there's no reminder left. So that is zero um, so I'm saying, like, divide by but it's more sort of like what remains after the division happens. Okay, And in case a few in numbers, if you divide even number by two, Obviously there is nothing gonna remain eso that that becomes a zero remainder. And that's where we actually say when it is zero. That means that number. So that's how modular stop operator works. Limit commenters. Because somebody that I was sticking a little bit of a long time to execute. Although it's not, it's not much. Tell me, actually comment all the older ones just so we can Okay, I have commented all the print statements just so we don't see much of the year. He thinks, OK, uh, in our log. All right, let's move forward. So, um, has he What else? Give me Can we go over? Okay, so one of the other example off funerary operator is negative. So let's say from and convert some number two a negative form off itself, then you can do in re operator. So let's say let three is equal to three. Okay? And let minus three is equal to negative. Have three. Okay, So negative. Here is unity operator because it's working with this one operator, right? Eso eyes goes to, ah, two plus all right. Now let's talk about comparison operators. So comparison operators are there are few. So, for example, there's a equal equal which checks for equality. So if a is b equal to be so, for example, if we create our num one equal to one in wire, numb two is equal to do so we can say print num one equal, equal number two. So this is simply checking for the equality off these two numbers and it is obviously going to evolve because one is not able to do it. And if you say not, which is an exclamation mark in equal. And if you say this is going to basically return true, because number one is actually not equal to number. Okay, Now you can apply greater limp and say is number one greater than number two and check for that. And it says now assaults because one is great when it's not greater than do well, one is less than two. Um, if you checked that, we're gonna see Okay, Yes, it is actually true. Um, so other than a lesson in Greg Lynn, we have less than equal to and greater than equal to. So let's say we say it's is it greater than equal to, um a number one is greater than or equal to number two and is going to basically returned false EST. Unless it actually comes back. There we go. Okay. Um, similarly, you can say is number one less than equal to number two. Now you execute that is going to say true because, yes, that is true. Now, if you say we had to and to ah, this sort of being truthful So reason you actually write sometimes this way is because you want to make sure that condition is like, you know, um is going up to that bone and stuff like that. So I say, if you're executing a for loop or lip is going up until 10. Inclusive, not exclusive. Okay, inclusive. It's like, you know, including that. All right, so that is a quality operators. Now, um, let's take a look at maybe another example how far equality operators. So let's take a look for the drink. Right? So let's say for the string of up equality, if you have, like, name is equal to world. Okay, then you can see if name is equally call wound, then print. Hello, world, honey. So, um, now, in this case just is actually really good example, because it shows you difference between one inquiry double equal, so one equal is basically assignment. So what you're saying is assigned this value to a variable all name, Okay. And here we're actually comparing them and returning through and fall to our falls. And we're saying, like if name is equally cool, which is like, you know, name is name equal. In normal language terms, we say, like, you know, is name equal to world. Um, if it is then print. Hello world. That's what that's what it's trying to say. OK, that's common. Tous and, um, take a look at another example. So you you can compare to basically to, um um, what do you say to two poles? So let's say if I would say if I say if, um one and dog, for example, is equal equal to and doc our or one in down right and we print something here, all right? So if you do that, it's basically going to print that something, because it's comparing first value of the people to the first value and second, barely off the DuPont to second value. Now let's say we have to and say, Brent, something else here. Oh, so we actually get something else printed because one is not equal to one is not equal to two. And that's why it goes to the else operation. So, for for two polls, that's all you can actually do a comparison using the comparison operator, right? Ah, okay. What else can we look at? So milk coalescing. Okay, this is actually very interesting. So it's called nail call late, I think operator. And this basically means that? Um Ah, you one unwrap and awful. And if ah, its value, if it contains a value, then return that value. Otherwise return a default value if it is no. Right. So, for example, um, let's say you had nil value, Okay? And, uh, you created this no value with int. Um, Optional. So you Santa, like when I was 30? Okay, now that's a non acreage. Another able non nil. And he said, um, if nil value is Cole lacing operator, that sort of you cannot play Is milk a leasing? Um, basically, check that and say, If no value can be something, then give me that. Otherwise, give me cause you okay? Don't throw in there. So if we take a look at non nil in this case, we're gonna get 30. All right, there. We have 30 right here. Now, let's say if I would say effort of over it said, like, you know, nail here. Now, in this case, it should not return nil. It should actually return me a default values, so it should return me zero in here. There we go. So we actually got zero in non male. Okay, so that is how? Basically, if let's say you have some little values that you are you're trying to evaluate, you can simply Nicholas them and and short circuit them to basically find out if you wanna consider that value test inside the mill. Ah, of able or, um, you wanna use a different year? All right. Hope? Hope that is. That is clear. Uh, all right, so I some part range so swift has ah, something will range, operator. And you have already seen that when we did this for group right here. So there's these three dots right here is actually a range operator. Okay. And this one is called a close range operator. Ah, because it runs from its starting value. Whatever your value, have to find that the left to the value that it's it actually and sent so basically value that they have disputed wide on the right. Okay. And it does not go beyond that. So once again, like, you know, if you had a before, if you had a for loop with index, for example, and you said index in 1 to 5. Um, in print index, if you run, this is basically gonna print 12345 Okay, now the not There's another radiation for it. This is called half open range operator. Which is this one, huh? That means start from here. But do not end here. End less than this value. So if we actually run this right now, going to see it only prints. 1234 Okay, because it's actually half filled high. Um, okay, so one sided range. There's another thing called ah, one sided range. Sufferings for this, actually, let's consider an example. So I'm gonna create Marie and down, we'll come back to creating a nori and stuff like that in future, so don't worry about it, if you don't know, But it's still in your simple. So I say we have names, all right. And, uh, if I create name one are threatening these. John Joe. Jack? No, for example. Okay. Um, So, um, there is a thing called one sided range and one sided ring. The way it works is like this. So you apply for name in names. First of all, if you execute this corn, right, All right. Uh, name. This is the way to, uh, it rate over your collection or it right over your group and print each and every and get each and every valley. So what we're doing is we're saying, Ah, create a for loop for every item that's actually inside names and assign that item into it every way we're called name and inside this block right here. You have access to that name that where you can do whatever you want to do with it. Okay, we're simply printing it. And as you can see, we're sexually It's actually, um oh, it's a joy. And actually Estrin I wrote to an and called Called a Jump. But anyways, um ah, print and you print the name the current name. Okay, so this is Are you basically print that Now, let's say if you only wanted to print names from, uh, second index up until to the end, So you would say you would create a one sided range. So, for example, you would say to dot, dot, dot Now that's from this and see what happens. So what yet is 012 and to the end. So arrays are zero based index. So, um, so you start with you Index one index Do next three Knicks. Okay, so what you're doing here is you're saying zero to basically run it from two to the end, Um, with which is print Jack and and and Oh, Okay. Now, let's say if you had Thea other way. Now guess what happens here. You actually run up, do that second, uh, second index. And you can, uh, even just have to, like, you know, join and Joe like that. And it's gonna basically ignore anything beyond would get, like, you know, more than more than one in this case. Right? So that is half open and half, half open and one sided ranges range half open. And once I did ranges. Okay, I hope that is, uh, that's clear. Let's move forward. And next, we are going to be talking about logical operators. So logical operators are are, like, you know, basically combining Boolean logical values true involved. And there three types that are supported insert logical, Not which is you have seen like you write a is equal to not be so. This is a logical not here. Okay. And ah, there's a, uh, logical end. So basically, you say you have seen the sun is also you say A and and B, which is like, you know, A and B evaluate these two when these two conditions are true, then actually proceed and say at the 3rd 1 is logical are which is, like, you know, either a or B truth and proceed forward mainly used it for, ah, lot of time. You use it for your conditional statements where you're typing it in. Um, if if else conditions in your checking for them and you actually do that. So, for example, I see you created a They were every ball called allowed entry. And you say this faults. Okay, so entry is not love. If not if not allowed entry, then you say print access denied. Okay. Now, in this case, guess what's gonna happen. You're gonna get set tonight. Why? Because he said allowing interest false. And we said if allowed entry eighth not basically so false and not operator becomes true. So if it's not allowed if allowed, entry is not basically true. I mean, this value is to true. Then practice, which means allowed entry. I allowed. Entry is not allowed and exits. Okay, Now, let's see if you had like, you know, to, um to conditions. For example, You had let air enter door could and he said, True. And he said, Pass heartiness can It's equal to fall us. So someone had actually entered the door court, which was successful. And, uh, the, uh, retina, which is R E retina scan. Ah. Did the bar set a false? So you can say if enter door code and pass ready. Now, scan. If those thes two values are true, that means it's actually give allow this per person in. Okay, So just say welcome to the world off, all right? It's apparently very, very secured. And he have actually passive. You have to provide your retina scan in, and and once you succeed that, then only you can get it. I'm just getting, um, or else he can say print a rather print. Um, Texas denied. Okay, so in this case, because it did not, uh, the person did not by its original scan, but he said excesses tonight. Okay, this is an example off in operate. Now let's say we loosen our security a bit and we say or okay, so we say if entered or cold is OK, so they have passed that, or if they've passed a retinal scan, let them in, All right. And we welcome them with open arms to the world of thrift. All right, cool. So so that is actually the example off off, like in a logical operators. And, um, you can even have ah combination off them. So, uh, I say, like, you know, you had, like, has door key id equals true. Okay, So he can combine. So you can say in the bracket, you can say enter your code and has dorky Okay. So if a person has entered the court and they have turkey, it's all then the if these two conditions validate to true or this velvet true, either one of those we should allow them in. Otherwise, you should exit tonight, and we welcome. Okay. So you can actually combine logical operators, so to do the traditional checks. Okay, Now, reason I put this explicit toe apprentices because it actually makes it easy for, like, you know, for code readability as though has, like for the priority, Which one actually takes the Kristen's. So, for example, be crafted, written something like this and would still allow that. And this would still evaluate, like, you know, to be the first thing. Um, but it's actually rather clear if he if we Oh, if we wrap them in parentheses, All right? And this actually comes to, um um operator, presidents, and, uh, this time, like, you know, and operator takes the president or, uh, or operator. OK, All right. So let's talk about this, this Pothier. And in the next video, we couldn't stop a huge topic that is, actually that has been quite complex and has been changing ever since. The circles and house. And that is actually string and characters. So we are going to be talking about string and characters in the next video. Okay. Hi. Thanks again for watching. And I'll see you guys in extra new 4. Swift Strings: hello and welcome back. And in today's video, we are going to be talking or the probably the most important topic, Um, strength and characters. So excuse me. Stepped has had a long history off getting some sort of change with every release within these drink class. Um, and most of the changes were, like, you know, really good. But so the genius, like, you know, they kept going back and forth basically between one design to the other. And that made it like, you know, one of the most start off topic, like, you know, where you you go and you try to learn, like in a was what changes had this new release and you're always, like, you know, curious about it so well. Luckily for House, a four and sort 4.1 I mean, there were some some major changes for but so 4.1. Ah, there's not how many off the major changes that they have introduced. They have added few things and made few things easier, but overall, it's actually pretty good. So we are going to be looking at string basically end doing like, you know, try to cover everything possible of it in the string. All right, so let's get started first. Let's create strength. Oh, you already know how to do it. But let's for the completion. Sinkhole. This created strength. This is a sample strength, all right? And, uh, if we execute that, that's actually going to created strike. Now, um, now that they if you want to create high, uh, strength with multiple lines, so multi line strength a less safe you create that he can created with triple coats. So multi find strength and you say triple coat, and then you start typing your string. So this is a multi line string with lots off content and that hand close that with triple course, Okay. And, ah, that is how he can create a multi line strings. All right, And, uh, see, next thing we'll talk about special characters like escape characters and stuff. So I'm gonna actually explain these home and some of these have already seen, so if you remember, we or probably probably not seen it. Okay. Uh, okay. So how the seat, um, slash two is for horizontal tab, I So it's just like, you know, eating the tab. Ah, a key on your keyboard. Okay. And then you have doubled back slash. That is actually a backslash. So, uh, with one put like reason, it's double because you escape one. So, uh, eso every single character, like, you know, it's going to be followed by a a backslash. And that means, like, you know, there's a start indication that start off a special character and he actually put a backslash then in. Okay, so let me do this. I said this is back flash. Okay. Next comes a line feed, which is Ah, the like, like, new line character. Um, so, um, snap CEO in, and it's called line feed. So basically, you you wanna starting a string with new line, you actually go to the line feed? Um, and we can actually take a look into example. Come, then. You have carriages are, which is like, hitting the return key. And that is, uh, Carrie. It's return. Okay. And then you have single court. So let's say you wanna put like a single coyotes. Do you Do you put a backslash single court and that's how you put, like you know. Ah, single quotation mark. And similarly, if you're a do like double coat you can actually do. Buy slash double court, So double coordination, Mark. All right, let's take a look at the example for Santi's. Okay, so we create our new strength sample, let simple sample special char strength, but it Campbell has created multi length. All right, And, uh, mixing you could do is we're gonna say yes. A This is this line has last d wade backsplash and slash and a long red back are and some single coat values scanned, so definitions. Okay, let's take a look if we made any hair bigger. So, Hollis, print this one because this actually getting a rather long so special character string. Let's bring that now on. Actually. Hi. This actually comment this right here? Because we don't wanna see any other prints statement other than the current one. Okay, there we go. So this line has, uh, this is the tab Space. As you can see, there's, like, you know, 23 taps in here, and there is, like, you know, backslash, and uh huh, that's what you have that backslash. One backlash showing up there and a new lank actor. And and if you noticed, there's a space. Uh, and then new line is stars. And then you have, ah, along with basically carries return, which is very similar to like, you know, the line and then some values, which is, like, you know, single court valleys in some definitions, which is type double court definitions sort. All right, so how little bit? A little bit off basic, but her shrink. So string is a series of characters with instruct and, uh, it can so anything that comprises, like, you know, anything that you see here is basically a, uh, seas off characters. And that's how they define it. Um, strength our string her represented by basically by either. Like, you know, uh uh, basically by Unicord collection of Unicode characters. And those Unicode characters have each east character have, like, you know, like it could be one character could have, like multiple, um, corporate multiple characters within that to make one character. And it's gonna be clear, like, you know what? I'm gonna talk about it because he got a little bit different from your ask I and the range is like, huge on, which is why I like united. It's it can support emojis and like special characters and other languages, like, you know, like a cute, um, symbol, like, you know, um, now, within the kind of trance and stuff like that, that's how it can make indo it. And, um, strength A concatenation is symbol, as it is, very simple, as combining two strings with plus operator and mutable teas managed by choosing between constants and very both. So when he actually define it, let her you make it stringer, that you make string as constant. But when you create as war, you created other mutable being able, okay, and spring is her. It's bringing out value type in swept, which means that when you actually pass string to your functions, you actually passed the actual value off the string. And it's not just the memory address that actually over for us back to like, you know, someone at that same location. All right. Surfed type is braced with, like and the strength of a few few use and a string. Like if you've used in the string, you can use a along with a string of all. And you can actually, uh, create something like how they say let, uh and this strings sample. So you can say, like, you know, for example, this is a string and and you can say so we can weaken type Costis, uh, gives the ads in this string. Um, we need Teoh import. So I see you brought here Hidden pork Abomination Foundation is to class that actually contains all the basic types. So the types that human are dealing something common functionalities related to the framework. So and it's string. I think it's a part of that. Yeah, they go in the now your type off in a string become sexually and a string hesitancy here. So if I print that, you're going to see it as an a string instead Ofit string. See Hennes Kaduna string type, which is like, you know, if you option click, it's actually industry. Right? Cool. So, um, see, recovered, Mostly line. It's ah, Unicode characters. So basically, um Okay, so what I was talking about Unicode character is like a collection of characters. So let's say if you want to create a dollar symbol, right, so you can say dollar symbol, our sign. And, uh, this is just gonna be one character, but you see, like, how many characters, it's actually involved. So you have backslash you have you curly brace on and then 24. And if you actually execute this, this should print, um, a dollar sign for us, which is one character. So if you do like in I know we haven't covered it. But if you do not lent our Dr Count, I think, Yeah, see, it's got only one, because it is a unique or character, so it's only gonna count it as one character. All right, so that is what it means her basically to be, like, you know, in the unicorn scale space. All right, Cool. Now, how would you? Um uh, basically, how would you define your spring as then? How would how would you totally created an empty string? So it's a symbolic, a great, like, empty string, and you just create it, Uh, and then you can check whether, like, you know, a string is an empty string or not. But there is another way to create an empty strength, another empty strength. And you can just call the string class default constructor and it's going to create another empty string class. Now, let's say if you want to check if it actually if it is, it is empty. And you can say if empty strength dot is empty. I print IHS empty strength. Okay, if you all right, I didn't mean to do that. So it's going basically print. It's an empty string because strings empty, we can do the same thing. Same check on the other side on the other string and, like, you know, that's gonna come with the same result because it is actually as we have effect. Um, it's an empty string and this is how you check for the for the string values? OK, now a string mutable to you talked about it like you are briefly, but here's his like, you know, a little bit more. So, uh, you can actually a mutate a string if it's sign, too. Do our and you can't if it's to find, do a constant right. So let's say if you had, like, you know, constant strength and, uh, found strange. Okay, So, uh, if you have that, I and a say constant strength as we go to something else. If you try to run it, it's basically going to be compiled tenor on it's going to say all you might wanna consider sending it to our well, we don't intend to modify it. That's a good thing that you're giving us the warming. We're gonna create a table and we could say variable strength now. And I got to say one I would say for a couple and variable strength, and this is something that you can do for contamination is a plus pickle, which means Rabel plus something else. So you know, you don't have to re type with the Babel name the name of a bow and plus equal and type your new strength. And when you do that, it's actually going to create. It's going to actually bend it to the Kurd fostering. Okay, here we go. One into its big pretend, uh, eso we talked about, like a string being value type. But that means basically strengths are passed with the function or the method, and you get your own copy or do we mean by that? So let's say if you had a far string function strength because I'm gonna pass it inside function sample, okay? And I say funk, some function you things today and I take a str in here and I would say print or str it's equal to Well, not a lot. It's not allowed to update your the the the available that's being passed in because they're usually constant. And the way you can override that basically can create the variable with same name. It's sort of like a trick, but But you're safely creating another another way able with the same name. That's what That's what you're doing. And you say it's g r plus equal, uh, string, but gamble And then you do print off str and then you print here. Oh, function Strange. Now if if string was ah e uh um reference type, it would basically how we actually for back to call some function, just trying punk. Okay, so yeah, so if ah, string was ah reference type, then sample dysfunction string would have bean changed to sample string, but it did not, which proves that it's actually value type. And when you actually supply string to a function, it's actually it actually creates its own copy. And that's on this, uh, it's using here. Okay. All right, let's move forward and let's talk about some characters, okay? so all right, like we discussed ah, a little bit ago. That, uh, uh, strength is a, uh is a collection off characters and the way we can actually look at those is like, you say, chars and, for example, dog And let's draw a dog emoji here. Um, like so. And then we say print, um, are are char, actually. And if I run this ah should print, they should print each character. And emoji is one character because of the unique old nature off this train. Now, let's say if you want to create, um, a character you can created by, like, you know, I say, explain me, exclamation mark on. And if you created just like that, it's basically going to create it as a as a string. And you can check that by option, clicking on it and, um, hold the often key and click on it. Basically, it will tell you tested the strength, but you can all right, that by specifying the type and this is another example where you actually do type imitation, so they're attains to character. Okay. Now, um, string, you can construct strength, are bypassing array off characters and basically initially. Just so let's say if we had, uh, dog cars, for example and we used this strength and this is a collection off character and we say basically, divide this up into Did you go? Uh, now we can say that dog strength is equal to string and we pass our this, uh, dog Char's has its parameter. And when we actually try to print dog string, you're gonna find that sexting as creating Hey, an actual string right here they got from the character, Right. Okay, so Ah, this Ah, the stock Water concatenation one more time Eso If you want Teoh in Katyn eight e character to a string How can you do that? So let's say you had ah strength gone GATT String, for example. Hello. And, uh, it's not lettuce uar. And you say gun cat strength plus equal work. And then you wanna add exclamation mark on it so you can simply do it by thing. Plus, it's not Oh, hi, have you My bed had a liking. It's complaining that some left Okay. Anyways, uh, gone Cat can't get string. Um and you say Doc append And this is how you can append other strength. But you can append characters. You can spend sequence off some sort of, like, you know, a way. That's what that sort sequence office he could happen. New element, basically as an element to the and which is where the most similar to, like, you know, ah, upend regular urban. And, uh, uh, the other one other overlords are, like, sort of similar, but e might wanna explore them in case you need, but most most likely gonna need her either there's this either, Like, you know, Ben in character are pending of the strings or a pending other, like, you know, array off strings. Okay, so let's upend. Um, exclamation Mark, uh, as Okay. Okay. So if I do pruned, couldn't get Frank and title run it, You're gonna see help? Yes. It's always gonna feel well, it's gonna feel because we can. Then we can define it like this plane, which are equal to this, and, uh, we go All right, they go. Right. So this is how we can upend character to a strange I. Let's take a look. At example, off A pending, like you know, is a like a ray of strength. Basically So I say, if I had, like, you know, e r r String, for example, I would say hello. Hello, world and exclamation and, uh, Okay. Cool. Yeah. So are actually space. ISS has the sun character. Now, let's see if you had that, you can say basically, let new string Yeah, string from away people to I can empty strength, for example Right now and then he's a string from a raid out append contents off in you stay our strength here. And then you say, friend, uh, extreme drama, right? Uh, and execute it. You can actually see Well, I'm a ghost reference Why? Okay, so they should And we guess reference. Why is every separates the contents off? Do you need? You need this holy during the early resc or Oh, this is a warning, actually, sinless Do you have in common difficult? It's good right here. Okay, So why is saying I left pin the contents off? Oh, it must be because of this because of this ambiguous reference. Let's try out this way. So it a string that's equal? Um, there are string, for example cannot be applied. You guys are so no, That is that is true. Oh, okay. See you. Try this dot Append count herself Sequence. They are String my sample. Okay. All right. Uh, this is, um Well, that's that's not that's not true, actually. I mean, you should work because ideally, a soft contents is for Okay, So I'm gonna have to get back to you on this one. Uhm and we can actually, uh, will take a look like you know what's causing this issue. But usually the constant contents off should work with, like, you know, any sequence, type and sequence. This is a sequence type what? What it means by sequenced, I basically is a collection. Well, you so it should actually work with Will. See. Okay, So let's not what string interpolation string and into her collation and string interpolation is, for example, like, you know, are constructing a strength barely with a mix of constant worry bells. Literal these expressions by using their value and Zionist string literal. Or it could be computed using code, for example, how you say, like, you know well, d a plier. Did you go to three, for example? And then you say, let message eighth equal to and you construct. So you say multiplayer? How? Times 2.5. If and then you actually created an expression here. So you say double and, uh, multi Claire, because the reason we're converting into double so we can multiply with 2.5, and that is going to give us a result. Fred, the computation written are ah, basically computation. Burn it right here. So three times two and have is five. So this is how you construct basically starting in population. You have seen some examples our leader. But this is one example where you're actually creating an expression in line s so I just want to show you, like, you know how that this is also possible to do that. I mean, for cold readability perspective. It's not actually a great idea. So out rather like, you know, creating a new wearable. So the new mo new de player, some like that and then do it here and basically Oh, no, it's not a new multiplayer, but like result of something quiet and ah, you actually create that. That's actually much more readable. We declaration look All right. Yeah. Um I understand that because regional was throwing an error because we have used red result of able named Admiral Stanley doesn't lets you do find that because you're changing its type in everything and we're redefining it. So that's like saying that, but yeah, So it was like, you know, more, much more readable cold than, like, you know, earlier. But you can have, like, expressions or within the string interpolation assault. Okay, No. Uh, so let's talk a little bit about Unicode. So what is Unicode? Unicode is in the international standard for encoding representing or processing next in different writing systems. And it enables you to represent almost any character from any language into a standardised form to read and write those characters and from an external source for such a six file or a webpage. So he can literally, like, right any any of character of any language within that within served using regard. Which is why I served two uses Unicode as a default. You guys getting ready at the default string constructor? Basically, foundation is based on all right. So, for example, let's say if you want to create even acute. So what? What a portal. Remember that said it's 11 character e a cute, for example, and you stay character and he created by constructing this string. So you say you how to Unicode e nine? All right, and thank you. It's gonna print and e with an accent on it. Right here. Yeah. Okay. So this is Ah, this is what I mean, like, you know, Latin, like, you know, or any other character, which is, like, you know, not regular English charter Sift can cover that. And you can have, like, you know where you will have, like, you know, those character strings as part of, like, you know, your string, and it will be, like certain would work it work with it like, just like a regular strength. Okay. And, uh, you can actually, uh, brink flags and stuff. Those are also defined character. So unless a U s a flag, for example, uh, and that it's going to be slashed. You Ah, one one f a and, uh, that actually. Okay, so I said Okay, sure. And, uh, slash you one one have eight. Let's try that. And it should give us United States flak. And there's a whole bunch on. You have to actually really like, type these codes you can literally like, you know, control, command space and for flags. And there we go, Like, you know, you have also flags like, for all the countries, and you can actually bacon and drop them, like, you know, basically as a part of string. Okay, cool. Now accounting characterised her to retreat The count of characters in a string I can use count property Get So what do I mean by that? Let's say if you were to count, um, characters in acute, for example. E e cute dot com Oh, it's a camp from So when you string a week in count strengths character. So that's a reach to be taken. Get string. That's a good example. And we can seem like you know, how many characters that has, how basically tall. And that is like, you know, including space. Okay, so 23456789 10 11 12. Right, So that's how easy it is to count characterised now Unicode characters when you actually remind them they are actually counted as one, although they're written with, like, whole bunch of characters of their constructed with the whole world of characters. But they're actually one character, right? Um, let's see. Now, let's talk about in disease. So, like, you know, accessing part of the string and stuff like that. So, um, say you had a, uh, spring call greeting. All right, um, you can basically get its first character by describing greeting, creating dot start index and, uh, as going to print Justin g. The first character. Okay. And, uh, if let's say you want to find the last one like the, uh s right here, if you wanna get the access to that so you can say greeting now, it's, uh it's not basically the last one. Um, but index before the last one. So that is going to print us the s okay now, because it's a range and the end index is the position off the last character assessed ring . But it's not a valid argument If your sub scripting Ah, a strength. Well, um, now let's say if you want I like, you know, bring something in the middle. You can say something like this so you can sit greeting and say greeting dot Starting decks don't off sent. Um, but I, uh come on. Offset dot By and uh, called on you need to find the next that sexually breathing don't index. And this is the one. A lot. So you say, greeting that start index and offset by, like, for example, seven. Okay, if you do that, um, is going to print seven times, basically, so on 234567 And that's gonna upset that and printing 70 index for us, which is, like, you know the value. Okay, uh, now end index again is in there because, uh, I this is this square record is called sub scripting, and it's not allowed to use and index evidence of sub scripting. And you cannot do anything after because it's going to be out off. So you're gonna cannot have, like, you know, greetings, for example, dot index And this after they cannot use it with and the next because there's nothing after the end index Third control in error. Um, and you can print, like, you know, um, individual characters off the strength by using indices. It'll so, as I say for it, for greeting, for index in greeting dot in disbelief and basically can say print And this gifts you basically access Teoh our individual index. Um, and, uh, you can use the Terminator to turn right, Like new, Basically to other pretty space. Or, like, put a new line. So let's see, if we had new line and, uh, could be trying to print this, it's gonna print each character in a new line right there. Okay, so let's get miss comment this out. All right, let's talk about in search in our and removing off seven characters and the strength So you can say you had, like, you know, you are welcome Hello, for example. And you say, Welcome that insert, okay? And he can incident New element. So let's say you insert like exclamation mark. Ah, and this is where you can defying the position. You want to put it in So you can say welcome Dr and Index Welcome, MSG. Maybe it's not there already. Um, re declaration. Okay. New welcome message. Yeah. So, uh, yeah, that's actually okay, that's better. So it's gonna penned. Hello. Ah, an exclamation more at the end. So that's but that's how you can insert and you can like you can actually remove, so you can say welcome. Um are sorry. New welcome move for example. Uh, now we need to compute the index here. Eso at two week stay new oak mas's stock index. And we need before in the next so dot and index going to get the last character. And we need Teoh basically, remove that, um which is gonna put us back, like, you know, basically is gonna remove that. That one capturing gonna leave Dia train without it. There we go. So this is just returning which character it had removed on. Then you have, like, the the whole character. Right? Um, let's talk about how to create a sub string. So let's say you want to create our suffering. So begins they some like that. So I see no create self strain value. It's equal Teoh Hello. Or situation. Okay. And we say index off, huh? Sub string you dot index, huh? Self character comma. We get that if it's not present and we actually get some string while you start end index. So get the index off comma, okay? And then resell strength basically the string into two parts. Eso we say let, um beginning if he could do sub string value and be used. Um range. So we say the double dots lead less than index. So anything before index hum we we would count as beginning, and that should give us just the hello part back. There we go, I and, uh, now, this is actually, if you look at the type here, it's actually string or sub sequence, and the way you can actually create it as a string, you can say, Ah, that new beginning is equal to a string, and you pass beginning into that. And that would convert the big name, which is, ah, strength of sequence. Do a on actual strength that could work with Okay, all right. Uh huh. For real quick for the equality, you can compare our two strengths. How would, like, equal equal? So let's say ahead are our let strain one it equal to one, and that string two is equal to one. If string want is equally all string to you're gonna print equal, for example. Um, help. Sorry. All right, there we go. So they're equal. And that's how you can actually compare and all the like, You know, um, some of the other, like, not equal and stuff also apply. So you can actually say. Not equal level just for the quality. And you can check for this basically being empty years like that at all. Um, all right. Says And I'm gonna print because it's actually they're actually, um Okay, now you can actually Ah, check whether ah, spring has certain prefix or suffix by saying, Like, for example, um, our sub string value dot has prefix where basically starts begins with and resupply some string here. So if you say a G, for example and, uh, we give it to go, I basically going to return that it actually has a prefix like like Eddie. And similarly, you can use it for. So string dot has suffix and he can say our explanation, and it's gonna basically come back. But the true alley asshole. Okay, if you wanna get ah utf eight representation for your string, you can simply say yeah for, uh, code unit in sub string value that utf eight. You can actually get that how? For example, gold unit that and basically, let's use the Terminator space. Okay, so it's gonna basically give you, um, give you the ask I representation off the strength. There. You go. So, um so that will give you the ascot representation. Now let's say if you want to be sure, you can say a bc Okay, for example. And I was gonna give you Oh, sorry. Should not be three c Think that and I should give you Ah for ABC Like hosko alleys for a BNC. Thank you. All right, Um and you can have, like, you know, basically 16 bit utf 16 representation by using utf 16 year instrument utf eight Okay. And, uh ah that's going to basically give you utf 16 representation which is like, you know, which includes the executor. But like, you know, there's some more characters that are also allowed in there are there apart, like I think, uh yeah, like dollar phase and stuff like that also included in their um Then you can like unicord scaler. You can also have like in a Unicode skill representation which oh, you really don't like you know it's issue. You enter 30 do and uh and you have to like, you know, no Sud up eight or utf 16. You to say I need Unicode scaler values, which is like, you know, I mean just give me the ask our values. I don't care like, you know, eight or 16 because you're actually working with, like, you know, ask how you can use it with that guy are like another. But this is going to give you Oh, so it gives you the individual character, But you have to actually say value. And that actually gives you the ask I characters for thes Gaylor like that. How? Right? 5. Swift Arrays: Hello and welcome back. And individually, we are going to be talking about her collection types. So basically Swift Bride three primary collection times are known as, ah, race. So I raised sets and, uh, dictionaries and ah, these are thieves are used to store a collection off items or basically hoping to fight him off. Same type and arrays are ordered collection now off value. So they're like, you know, ordered sets are a Norden, our collection off unique values. So that is the main difference between a raise and and sense. And dictionaries are also on ordered collection with key value pair Association. So ah, rays are ordered. So it's like, you know, the same order that you put item in, it's gonna come out, and I mean, unless you're putting it at index or something like that. But, uh, but if you just insert an item, um, and you get it out, it's gonna be like, you know, in the same order that you have deserted sets her. That is not the case. It's actually a non ordered and its Onley unique values, so it cannot contain or it does not contain, um uh, duplicate or like you know, you had to pick it Values. Basically, dictionaries are basically Do you have a key? And you have a pair and you have a collection off those, and we're gonna begin to take a look like all of these, um, one by one. So hope you're clear with the distinction between the three and uh huh. Now, actually, let's get started and start are exploring a raise. And so, first, how would you create an empty rare How do you create in race? So I say some and we create and we open a square bracket close square record, and we say int all right. And, uh, then we actually tried that. And that is how we create ah, race. Okay. And, um, how would you append something internally? So it's actually very simple. He say some instant start append and your penned a new item, and that new item would be like, you know, the type that you have actually specified here. So I says, like, you know, and because we have a special right here, if you would have, like, specified, like string here, then that would have been the case like here. New element would have bean a string value. Okay, so we're just going to say, like, you know, men three. And basically you can print, um, uh, count for some incident counted to see, like, you know, if it had made it into our way or not, Isis is still executing the old chords. That's comment, Dad. And, uh, I felt a little word being display. Somebody let me do this. Let me call it the whole thing gets already seen it in this pretty straightforward stuff. So your comment all that yet? Basically go to our section right here. Go. And just so that way, have ah, just one item, Um, in the in the array And, uh, that item apples to be three that we inserted. Okay, now we can print three by simply saying some ends, Dear. Oh, arrayed. Start with zero Index zero. Yeah, your index. So what sent to zero index is three. Ah, you can reassign array into empty. All right. Basically, you can say, like, you know, All right, I'm done with using it, discard everything and re initialized with with empty. And this is how you do it. So, basically, you just but, uh, scored records around in hand, that is, that it's how it's actually renationalized. Okay, now, how would you create an array with default values? That is again, very simple. Sees a lesson three inch and you'd say array and, uh, open record. And look for repeating overload and arguing, especially by the count in integer. So we can say repeating is zero or less repeated. Would one let's put like one and no when when we initialize this and count it 1/4 3 So we need three values that needs to be inserted in this in this way, And if you take a look, it's basically in started 311 once inside the all right I like, um, Now we can actually. So let's say we create another array right here. My state tree are Thank you. Three, three more. And so, for example, we say repeating in this RV repeat, like with three for three items. Ah, you can actually uh, uh, create in Newry with, like, six. And by saying, Ah, three and plus three moorings. And this way you can actually see that theme. Plus operator has been overloaded. Teoh append to ah raise and basically If you see here, we have added +111 and at the end we have added +333 as well. Support of these are inserted into a single right. Okay, now we can initialize our way or we can create a race with a literal tearful So we can say life's a shopping lift and we can specify type here. For example, you can't say like it's gonna be a string type and we need milk. And, uh, we need bread. Okay. And execute. It's gonna initializing array with milk and bread. Now, you don't really need to specify if you're types are like, you know, if you have to find types are really fuelling exercise values. It's actually gonna implicitly infer what type is going to be OK. Um, now, how would you check if you're array is empty? Well, I can say, um, Lissa shopping list is empty. And uh, uh, this check is gonna tell you if it's empty or not. I just returns false here. Okay, Now, how can you append more items? So I say this I had one more item into are shopping less and, uh, we're gonna penned this time maybe eggs and our ray has grown into, like, no, with one more item and three items. All right, so, uh, Okay, Cool. Um, Now, let's see, like, you know, how can we append more items using plus equals. Plus equal is something that works. Arias Also, we can say plus equal and can say soda, for example. Uh, and this is going to be in all right, Eso you add one more item. Essentially, what you're doing here is you're creating another array with elements, and you're just to close it plus equal and that it's going to add items. So that is why you have, like, you know, shopping. I didn't plus equal. And you can define any number of items in your array, and it's gonna basically insert them. Oh, okay. Now insert using subscript. So basically, you can say, um gets a shopping list at zero. The next insert basically do milk. All right, So what's gonna happen, basically is, um, it's gonna insert that, And if you put a shopping list back on, you gonna notice that our values are I really is overturned. Um, with this so under it is is not insert update using Okay. Now, um, because insert is basically just append insert instrument insert ad and stuff like that we can look at now you can replace how stuff in range so you can say shopping list. And, for example, you can say basically, or you get basically a pen or it's so safe for 26 we need a few more items, and those items are bananas and some apples. Okay, uh, if he execute just right now, um oh, I definitely okay. They saw a range. Want to trade? Okay, there you go. So we get, like, you know, 123 We get this new items basically replaced. So at the next one, and it in next to it's basically replaced bread and egg to banana apples. That's how you can place them. Now, insert at is something you can insert at particular index. And this is one thing that we were actually that we were thinking that we're going to hear , but yeah, this is it. Insert, uh, and you say insert you string at So you say you can say, like, you know, eggs. Put it back on at index one. Okay? And if I but if I print D. Ah. Shopping list one more time. Um, we're gonna notice that eggs are back in place. Now you can room so you can say, shopping list stuck removed at unless they wanna remove second item, which is, like, 1/3 item I second and exhibitions. You don't want to so open in us. And I'm gonna print our shopping list. So remove at also returns, like, you know, which I don't have removed safely on the you that you can use it. Um, yeah. I just realized that I have felt it. I spelled it wrong. Okay? No, it was all right. Okay. Uh huh. All right. Um, so, yeah, but And it's a roof now. And now let's talk about start by removing last item so you can say shopping with start, move last. So you can actually removed every last item off from it. And that is T. So our shopping listers basically gonna be different, but, uh, shopping west, it's going to have, like, one less item. Yeah, uh, let's say if you wanna remove, say okay. We have seen, I think all right. Right. OK, all, um, for more everything. And then it's basically going to remove everything. And you said your array to, like, empty And that should be more all. Oh, keep cap. So shopping the start move all keep capacity. True. Um, that's coming, this one and on it. And if you look at a shopping stuff, count that capacity. It's gonna basically print however many number of items that that had, like, you know, it would actually keep that capacity. So it would not really get memory. Tow it. If, in case you want something like this, he can actually use removal. Keep capacity. Okay. Now, how can you tried over so you can say for loop And you can say for item in a shopping list , for example. Let's common. That's so weaken. See? Was going on. And you can print, um, items. All right. Okay. And this is basically going to huh? Print of like, all the Yuh items for us. Now, this one is basically just, like, number of counts that we have that we have actually bring it. Get showing up here. Okay, so now it's gonna show correct. Right now we can use we can also use a new rate and in great is actually something that gives us index and values. So, for example, we can say for on their two values and get index and value, uh, in shopping with stock in new, right, So enumerated, Basically, reason it's different from this biggest. It gives you an actual item. And I say, if you wanna have, like, you know, index off the item that you're currently in front of God than you would like started to enumerate, uh, and then then you can get, like, you know, the index. That's all. So item at, um, next is Bradley, and that is going to print. Adding that theory is to look upon itself, for example, if you need to know if you need to do that. Okay, so this was, um I I a deliberately actually kept very, very targeted eso that's that's the former that you're gonna follow for our future years. Um, but yeah, this is all the wreck. And, uh, in the next year, we're gonna explore sets. Okay. Thanks again for watching also you guys it next year. 6. Swift Sets: Hello and welcome back. And today we are going to be talking about set Ah collection. So basically said eyes, a collection type that stores are distinct values off the same type. So you define a type offset. So let's say when you create us that if you create a set off string, um, then, uh, you actually create a collection off string type at that camp contain, ah, unique value. So there is no duplicate allowed within a set. And the second thing is, there's no defined ordering. So when you insert an item into the set Ah, you, uh, kin your cannot ensure that item is going to be coming out in the same order it can come out in any order. Um, right, So that is the main difference between statin array. So let's go ahead and get started. Um, first thing, the most important thing is in order for, um ah, In order for you to create a set off a type, the type has to be habitable. Ah, and most of the basic types, like string into double bullion. All of these types are already hash able. Now what do I mean by hash bow So if let's say if you create Ah, variable. Um uh, I NJ in type if I say i dot hash value. And if I get this basically, um, that means that this particular type conforms to hash Hubble protocol and can provide hash value off I NJ. So if I do this comparison right now, it's basically going to return me a true value because these two values are there. Hash is getting basically calculated, um, based on an internal algorithm, but their hash values are the same. That's why this competitive returns true. Now, let's say if you want to create your own customs type and you want to use it with set, then you need to actually make sure that it confirms do Ah, this, um ah, protocol. Ah, hash of all political. Right. And that way, um, you can basically, um, make your custom class or a custom object. Ah, Custom class or customs trucked or anything? Um, basically ah conformed to set. You can use it with set. Um okay. So hope that is Ah s clear. Eso They're scared. Storing. Let's get fistic. Look as how can create an empty set first, so we'll create letters, for example. And let us it's ah, set off characters, okay? And, uh, we will create that thing. This is how you create an empty set. Now, you can insert, um, values in it by using insert on add new members of the state if I add a and let's add another one, Um, be okay. Now, if I want to know our stuh was the count on basically the set is I would just a letter start count and it would print me too. And as easy like when you insert you actually get a pupil back, which says whether the insert was successful, insert operation was successful or not. And the second thing is, member after insert is basically a so member after insert is basically it's just saying, like which, which item you have just inserted in case you need to actually perform some some sort off operation after the insert has been done. Okay, so it returns a triple. Um, Okay, so next thing, how would we actually, um, empty effects? So it's very simple. So we just say letters is equal to an empty right, and this is basically going to empty out our set like this way. So as you can see, it's basically reset to the initialization state. All right, Now we can actually, um we can initiate are, like, you know, create a set with a ray literal, for example. Ah, are, um letters to, for example, create another variable off layers. And, uh, this is off typeset and basically strength. No answering our characters. Hey. And you can define a real little here, for example, and this would create and you set for us, as you can see, how we just are creating a real literal and we assigned it to set and it created and, um, Ray are basically created. It's set for us. Okay, So this is how you can actually use set to create a very literal now, Um, if let's say you were using now, this case you were using string. But let's say if you're using strings, I mean, thats case, we're using characters. That's why we had to actually specify it. But let's see, if you re using string, um, you can simply, ah create that without specifying a type off a set. So favorite, for example, generals, his equal is a set and redefine type jazz, rock, ethical and hip hop, for example. Okay. And if you do that, huh? It's going to create, um, a set off type of string for us That, um So this is how we can, um, weaken, basically. Ah, create set. Ah, ways. Different ways to create. Set. We can check again. We can check count by, uh uh, asking for its count. And it would return us like you know how many How many How many items are there inside the set? Um, now we can, um we can insert the way we insert item. You have already seen that. So let's say favorite generous out insert. And if I would insert country, for example, um, you are and there will be a bizarre that. And if I try to print that, I would actually get the a newly added item a Davidian. Okay. Now you can remove items from set you thing, remove, um, function. So that's they removed. Item is equal to, and you have to, like, inhabit it just returns, removed items. So, like, let's say I say we just don't care what it is. We just remove. Remove a member off basically country. Let's say, for example, if remove country and print every general one more time, um, you noticed that it returns the item that it had actually removed, and then we can see our set is updated with, like, you know, with new Wellies or died. And that was the move. It's basically gone from there. Okay, so, um, how can we check if set contains some items so we can simply do like, you know, favorite recipe, for example, favorite general start contains. And if we say, for example, funk music, um, we know that it does not contain funk music, but begin, just just try to search for it. And we can now search, for example, that contains, um, jazz. Um, if it contains jazz or not, jazz is their station return true over there. Okay, Now, how do you a trait over a set? So you can simply just do foreign. So let's say for genera, um, and favorite cameras and you say print tundra, um, you would actually get all the turners are printed right there. Okay, um, now you can actually sort, um, basically genres so you can get assorted list. So if I just add dot I got sorted. Ah, you get, like, a sorted list off genres actually sorted list off. Um, let's get our printed basically. Okay. All right. So let's let's see some of the unique operations. So sad comes with some set operations, such as combining two sets together. Deter mining, which were leaves in two sets are common which are not common, which are two values contained, basically present in all sets or none of them are present in the same value and stuff like that. And we called. It was like union intersections, attracting symmetry differences, super sets, upset, disjointed stuff like that. So that's what we're going to take a look. So first, less create some variable. So begins a odd and bursts. And, uh, this is off typeset, and we're gonna use a real literal to create that. So one, three, five, seven and nine are our number. Stand down. Even numbers fit. And we have 02 46 and eight. Okay. And then we can have, like, you know, single, for example, single digit prime numbers. So all the prime numbers that actually come before a 10 are basically we can have those here. It's all that's another, um, Grable that were created. Now we're gonna start operating on this. Okay, so first, let's get ah union done. So we're gonna say our numbers dot union and we give another sequence of you say even numbers and we're gonna print this sorted, OK, see, if you notice when it actually executes, it's gonna combine. Are these 22 sets and basically going to produce a new set that is going to contain 0123456789 All right, Now, if we try to do intersection, which is like, you know, what is the common elements we can say? Like odd numbers start intersection. And in this intersection, we say it's at any intersection with the even did it That's sorted. Um, we gonna get something. Nothing, because even though not does not intersect at all. But if we say Lord number our numbers, for example, that intersection are not insert inter section Ah, basically single digit prime number that sorted for example, this one we should get something. So between these do we have 357 that are common. So we get those okay now a steak. A look at our subtracting. So I'll if they odd numbers that subtracting other sequence and other sequences, for example, issues single, do you prime number doubt sorted. Um, and we're gonna basically subtract whatever is in there and whatever is. Ah, it's basically not so if you notice one and nine are present in hard numbers, but they're not present in, um, single digits prime. So that is what is gonna print. Okay, so basically, it's gonna take these numbers, subtract, subtract, like you know, these. So it's going to remove all those items that represent here and here and gonna leave whatever it remains in this set because we're operating on this said as a primary set is going to subtract, leave those numbers that are present here. Okay, Now let's take a look at another example. Are basically a similar example off, like, you know, our numbers start symmetric difference, okay? And this one is very interesting if used to same thing for symmetric in difference and do sorted watch what happens to your new away that gets returned. So in this case, it's not only returning one and nine, which is actually present in our numbers but not president in singles it. But it's also including two that Means is basically taking the difference and considering both of them and combining the results that are not presenting either of those. Right. So hope that actually makes some since, let's move forward with some our values, like super sentence stuff. So let's say we create some variable, some more available. So we say, like, you know, house animals for examples are and we'll, for example, in this case, will use emoji is so the search for dog and ah, such for a cat. Okay, uh, both of them are house animals. Okay, Um, basically pets. And then we'll create another one farm any month. And this one are we gonna have basically how? Let's get, uh, maybe chicken, By the way, control command space again is he felt good for launching emoji. We know, um, sheep. A couple more. Um, so basically, dog and cat are farm animals. It's also you can actually copy does as well, and, uh, now we can get city elements. Are city animals, city Any moulds. Okay. And city has so quite interesting ones. So there is one. Um, says city usually have bird, so you can get like we can probably take this part. And, uh um, they also have mice, or most have you got so we'll take this one. Okay, so these air city animals now this operate on these. Okay, so this, for, say, check for super sent. Okay, so if you say house animals, that is super sent off farm animals. You're right. So you're checking your house Animals is a Oh, sorry. It's a subset off farm animals, and we know that it's a subset because farm animals actually include both dog and cat as well. Now, if you think is, um as do it in. So this is actually right here. And if we say is super set cough farm animals, this case is going to say no, because how's animal does not contain everything that farm animal contains? I mean, other way, other way around would be true, but it's not going to be true. Like, you know, we before house Imo and for minimal. So, for example, if we had a farm animal that is super sent off housing, Okay, so this far really will contain all of those that are in house element house animals and more, which is actually true. So it's gonna be a secluded turn. True. Okay, because for mineral contains dog and cat as well as like, you know, some other. But it is a super set off, um, house, and I hope that makes sense. And then subset is simple. Basically, if, like, you know, house animal is it's upset, basically. So house animal is within or one of the one of the values are some of the values off farm animal, which is true. That is why it's a subset. And let's talk what this joint eso we say for minimal that is this joint, okay? And we say city animals. All right, so this one is going to return True, because these two are completely separate. There is no intersection whatsoever in here. Now, there say, for some reason, chicken moves in the city and becomes a city animal. Now, this is going to become false because now you have you have an intersection. So so however, this joint you can find, basically, if the two sets are actually completely separate or are not okay, so they're gonna have like in over the do sets have no values in common. That's what district minutes are right. So that but that it brings us to the end off, um, sets and ah, in the next video, we are going to be talking about dictionaries. Okay, so I hope you guys enjoyed to studio and I'll see you guys in next video. Thank you. 7. Swift Dictionaries: Hello and welcome back. And in today's video, we are going to be talking about dictionaries. Okay, so, um, let's get started. What are dictionaries? Festival. So a dictionary holds association, associate ID, keys and values. So basically, it's a collection off key value pair, All right? It does not have any ordering, and each value is associated with a unique E which acts as an identify for that value within that dictionary, right? So And I'm like an array items in the dictionary do not have specific order. So this is another one that does not have any specific order. So when you insert the item, you don't know where which in which order is going to be present or it's gonna live. Array actually guarantees that, but set in dictionaries are does not guarantee that. Okay, Now, um, how they're several use cases for victory, and ah, I mean, that's one of the meantime that that's used for, like, you know, your web responses. When you get Jason response, you get like, a lot off a lot of time you get actually dictionary because it's actually a key value pair , and sometimes it isn't a rail dictionary and stuff like that. So in one of the immediacy is like one of the justices that's gonna come after this about like learning to create APS. We're gonna basically see how we use dictionaries to basically to do some some of the common things within within a wraps when we create them. Okay, so let's get started. And, uh, or we're gonna do is we're going to start with these targeted items in mind. So ah, first, let's learn how to create a dictionary. So we create a dictionary by simply saying, Let's say names off in teacher, Okay? And we say int and strength and any size. So this is how you create a dictionary and and dictionary. Basically, um, you have 1st 1st thing is your which is your key, and string is your is your value. So, um, they create an empty dictionary, and now you can start to populate this. So the way you can populate this is basically saying that's a number off names. Often teacher and he give 16 for example, and you say six t okay. And if you try to print names of integer right now, it's basically going to return that key in the valley. All right, Now you can create dictionaries with are, like, you know, dictionary literal. And, ah, this is how you can do it. So let's save agreed airports, for example. And you define string and string as a type, so KIIS strength and values strength. And then you say, um sfo San Francis. Hi. For some reason, I can't spell San Francisco, man. Um, and I live in the city, so Okay, So, saying for him says says Cisco, there we go. All right? Sometimes it's easier to type, then actually think about it. Um, OK, so, uh, the other one, um, that we that we can think off this Probably see why y Z is, um is that Toronto? So And there's another one. Do you be, which is, uh, Dublin. And it should be a strength. Right? Safe. If you print airports right now, are you gonna notice it's basically going to create. It's going to give you the list off. Um, off those airports now. This is interesting. I remember we talked about that dictionary does not hold any sort off ordering. This is a perfect example for that. Now you can see he inserted SFO first, but Dublin showed up for the first, which was last one, and SFO's showed up second and Toronto showed up as the last element which is entered in the middle. Okay, so again, dictionary does not hold the ah, the index already lied. Ordering. And the way you actually search section, he has basically look up the fields. Okay, No, let's Let's say, um you can you want to, um, get the count. Okay, so you can say airports that count and this should give you a count of three. You can check our dictionary if it is empty or not by simply saying airport is empty and it should give you false There. Now you can use subscript to add items. What do you mean by that? So you can say airport and let's say we want to add, um, a letter, which is London airport, Right? Um, it's it's London Heathrow, but, uh, we are doing it so we can use we can use another example to update this. So, as you can see, our history now has ah, London as another key. OK, And, uh, and we have four for rallies now. Okay, so that can't video. Now you can update um ah, a member off value off dictionary by using self critical so he can say airports and we can say L h r and you can say it's actually not London airport. It's London. He through airport Heathrow. I think that they pronounce it. But anyways, um, everything airports. And if you try to print it, you're gonna get London Heathrow Airport being inserted are basically being updated. All right, now, that's that's one of the one of the way to update. But there's another way. There's, ah, function called update values update value. So you can say airport, airport start update value, and you give it a a value. So let's say if you don't say, is that doubling? We say Dublin airports, okay. And for the Kiwi say, do you be And, uh, there we go and we have updated our, um, dictionary. Do you have a doubling and listed as Dublin Airport in self having it just doubling. Okay, Now, how do we get valleys from industry reached Simply say airports dot um, our airport and give it a key. So let's see if I say do you be right now It's going to give me the value off Dublin airport. How do we remove items? So he says say airports start removed value and we give it a key. So do you be, for example, and, uh, if we execute that size going to remove Dublin and, uh, but Sprint airports, So we know it's basically moved it, and, uh, it has, in fact, moved it. OK, now, how can you trade over? So they're ah, there's foreign for that is also and this time it returns key and value Pair in. Um, say your airports and you can simply print, um, please and value and basically se ki and, uh then you give it back to you and it's going to print a key value for all of these. Now you can it read A were keys for decree by saying, for keys, key in airports are keys. Okay. And if you print that, it's going to basically give you key for all the keys for the dictionary. And similarly, you can get our values for airport for a dictionary. So airport and you can print. But how do you like so? All right, there we go. And this again, Princess. And to the end off victory discussion. So we are done. Prediction. Rees. And in the next video, we are going to be talking about loops and control flow. Right. Hope you guys enjoyed the city hall. See you guys the next video. Thank you. 8. Swift Loops / Control Flows: Hello. And welcome back in there today how we are going to be looking at loops are basically control flow. So, uh, so we're gonna take a look like, you know how we have, like, various different kind of loops within, um, except and how basically you can it rate over a collection with the way it's different with Eastern ways. Okay, so let's get started. First, we're gonna check out foreign loop with a re. You have seen this, but just for the completeness sake, we're going to discover it here as well. So I say we have, ah, an array with some names event and, uh, lost one, Jack. All right. A lot if we if we wanna it. Read all these we just say for name in names. And, uh, we'd get a sprint. Hello? May. All right. Let me come into this old cold from the last video, because what's gonna happen? This is gonna execute, That's all. It's gonna make car program brand slow. So we got and we have, like, you know, it. Read it over. And we have basically saw how we can print all these. All right, now we can do have something similar with the dictionary. And this is another thing that you have seen. But let's take a look one more time so a number of legs get equal, Teoh, and we're gonna count anymore. Or are Yeah, animal legs off animal or insects? So Spider, for example, has eight legs and, uh, and has six from, you know, cat have for and we can just say for animal name and leg count and number off legs. And you gotta print basically a print there. Um, family name has have basically animals, like, you know, and spiders and stuff like that. Um, leg count. So it's gonna say this animal has these many legs and stuff like that. So and have six. Oh, what legs? Hands of 66 And despite have AIDS and cancer for lex Okay, so that is very simple and straightforward. Now, this is another one that you have seen safe. You want to a trade over a range or regular for four loop? You can use range valuable. So you can say, for example, for index 1 to 5 Bryant in next. It's just basically just simply going Teoh print index. I wanted to be five. And he can have, like, you know, half close range, which is going to print up until four. All right, um, we had that when a copy, despite a quick and, uh, basted hair on. Uh, just do that. There you go. All right. Okay. So, uh, um, let's say if you for some reason, if you don't want to, uh, use index. So, for example, right now, if I just do this, Brent Hello? Okay, if I did that compiles its going to suggest that well, you're not using this. So I'm not Consider removing and replacing it with underscore. And that is actually a valid point. Why create something that you know you don't wanna use? So any time you don't want to use any value, you can simply replace it with them and their score, okay? And that valley is no longer going to be acceptable to you, But it's not gonna have any memory assigned, that's all. Okay. I hope that makes sense. Uh, I'm gonna actually copy that, and it's all day basically basted here, just in case. CTO, you know. Okay. All right. So use off strain. This is something new, and it's very, very interesting. So let's see if you want to, um, instead off, Uh, instead of implementing one by one you want to increment like to any time or for any time In olden days when you had, like, four loop you could have been I plus equal to or I plus equal five. And it would actually skip those now and get some served. Four does not have that way. So how would you go about doing it now? Instead, Off having that of stuffed actually provided a function in that function is called, uh, tried. So let's say, for example, we say Dick Mark and it's a tick mark in, um and we just say stride and stride has two overloaded mattered study. Just ride through How, which is the transit sequence from the starting? Well, you the words and possibly including the end value and stepping by a specified amount. And, uh, Ritter the secrets I'm starting to ah, too early, but does not include an end value and step by a specified amount. Okay, so we're gonna take a look like and how they're different. But let's take a look. 1st 1 So we gonna start from zero. Okay, We're gonna go up until maybe 60 minutes. So we less TV. This is a clock and only prince. Five minutes at 500 Control. OK, so it only Prince 5 10 15 and stuff like that. And then we're gonna say for the interval, we're gonna give it five. So it's gonna basically jump five, um, at a time. So instead of, like, inclement one is gonna increment zero in the next five in the next 10 and 15. Okay, so if you print tick mark right now, you're gonna notice that it's actually jumping five strides any time, Okay. So that it's us. Tried? Ah, that's one version off stride. Okay, let's take a look at the other one. So let's say if the do dick mark again and we see each stride through start from three, okay. And, um uh, go up until 12 and basically in thoroughly three. Okay, I sprint us and you can see Let me actually current all these others just over a year planting only this one, Okay. And all right, this is X gold bug trying to being stupid. Nothing else. Okay, So as you can see, it's Ah, basically 36 nine and 12. So it's excellent implementing three at a time, But let's go back one more time in take a look what we were having at that time. So we were actually including zero up until 55 to 60 was not gonna trigger, and it would end before 60. But in this case, a sexually gonna go through. So it's more like, um, close range were says this limits have range. Okay, so just marked that distinction. This one is, um, close to equal into, um I say it's more like i equivalent to, um How fringe our half are you 1/2 open range. Okay. And, uh, this one is calling Teoh close. Strange. All right, so that is the main difference between thes cease to okay, now then be held my group. So why loop is is another kind of traitor, and we can do is let's say you can create able instead of creating a four loopy can create , like for I is equal to one in while I is less than 1000 for example, and this is very can actually do that stride thing where you were evenly and you can face. I start equal to the basically increment I times two and then basically print bust and then increments that way. Okay, so let's take a look. Execute that. And as you see, it's a blueprint 12 for 8 16 in fact, fall. And if you have, it would have done like this and basically said, like, you know, it's unequal 2000. Ah. Then also, it's gonna do it because next ranges from the doctor for yeah, next reindeers wants to force a few do, but to four it's basically then a friend 200 to 4. So we got all right now. Ah, will be while is Ah, actually exactly same as ah duo and ah, since Swift has changed the meaning off do with something else, especially for the air handling and stuff. That is why they actually, they had, like, you know, it makes more sensitive. They could pre down place anyways. Ah, let's take a look how that works. So we just say, repeat and in a difference between and gets you for advice, how do while loop works? Um uh, in case off, uh, while the, uh, condition is evaluated first and then it goes into Luke. So you can guarantee that that loop is not gonna execute until the until the condition is is actually met. Now, in case off, repeat, while you can guarantee that loop, it's gonna execute at least one once, because the, um, condition is going to get checked in the end, off the loop. Okay, so I hope that differences it's basically ah holds up. So, as you can see, like, one is not equal, not gonna be equal to do. And if this would have bean true, like, you know, in olden days, Like where? I mean, in the previous case, not novel in days, but in previous cases were, like, you know, years checking the condition first and then printing it, it would have not printed. Hello. But in this case, it's guaranteed. That's gonna at least execute once, and then it's gonna proceed. So that is why that's the main difference between, like, you know, these two between the while and the read wall loop. Okay. Um, so that is, um, it for the studio. In the next year, we're going to be exploring our conditional statements, basically, if else which and, uh gonna look at some of the variations of that, and right after that, we gonna jump into ah functions. Okay, so hope you guys enjoyed, uh, this radio and I will see you guys next week. Thank you. 9. Swift Conditionals: hello and welcome back. And today we are going to be talking about conditional statements. Conditional statements are often are useful to execute different pieces of code based on certain conditions. How that have bean are fulfilled. And if you want to run some extra, our piece of court Oh, within an error occurs or you're display some message when some value becomes too high or too low and stuff like that. That's when you actually make use off our conditional statements. Now, Swift provides are two ways to add conditional statements. Others if, ah statement and ah, there is a variation for if which has if and else. And another one is if else if basically these are all variations off if and then he have switched statements. How which is, Ah, little bit better student for more complex conditions with multiple possibilities permutations on. And it is also useful where you have a pattern matching. You want a match up better that can appropriately help you branch your code and execute appropriate court at our different pattern massed on and stuff like that. So let's get started with, um if statement So what we're gonna do is we're gonna create a simple available and see, like how it works. So he say, if Temple essay in for tonight is ah, 30. Okay, so we have very well that's actually storing temperature. And the current temperature that we have actually stored is 30. Now, if, um thea temperature in Fern, It is less than equal to for example, 32. Then are we gonna print? Oh, it's cold. Okay, um, now, if we if we try to run this asses, what can happen? Basically, it's not going to execute anything because our oh, it's actually gonna execute. It's gonna execute this print statement because our value eyes still less than equal to 32 . So it's gonna say it's it's cold. But let's say if you say like, you know, if it's 33 you try to execute it, it's not gonna execute. It's just gonna sign because this condition is not are getting satisfied. So this piece, of course, is not getting. It's not gonna get executed now, in case, because it's less than equal to, and we have already seen what less than equal to me is. Basically it means something that is less then, or is equal to so, like, you know, less than or equal to say, Freeport liking a 32 here, this black off court is going to execute because ah, 32 is equal to the reduce of that condition also satisfies. Okay, Now, let's say if you wanted to have this exact sing condition. But if if the condition is not that you want to execute a different piece of gold, then he can actually use else block in our block. He can simply say, um, not that cold, maybe, for example, And if you try to execute this one, you're gonna notice that it actually executed this else part, which is saying that, Hey, if the condition is not met, well, he can execute this particular piece of gold. Okay, Hope that's, um that's clear. Now, um, let's say if you wanted Teoh, if you want to just do something, like if our else if, um, temp in front it it's greater than equal to 86. Okay. So is greater than equal to 86 are the last condition that we're gonna say ISS else. Um, we're gonna bring the same thing here. Oh, just base your hair and you're gonna say, Oh, it's really, really hot. Okay, So if you try to execute this asses right now, basically first of all are less than equal to is gonna match the test. Particular code is going to get executed. Now, let's change the strategy 33. And when we change that this particular block, God is going to get executed. Now, if you change this to 89 which is pretty hard and for a nice um, if you change that to 89 well, cells like you know that it's it's really, really hard, and it's executed this piece of code. So as you can see how we can actually use if else if and else if it l if else if Okay, so if else if and else. Okay, so now imagine if you needed to do this like, you know, for, like, 15 different conditions. Well, that it would be crazy, because then you have to do like else they felt safe else. It's like a whole bunch of times. That's where ah switch statement comes in and out. Strips switch statement. Actually, ah compares against various different possibilities and and then executes Ah, particular appropriate block off gold based on basically just one pattern with the first pattern that was matched to successfully. Okay, so So it's only it's only it only matches one like, you know, first pattern that was that satisfies de conditions. So let's take a look. I feel, say, create some char and off character type, and we say it's ah, level. It's maybe see Okay. And we say switch and give it some char and pattern is a first a brained It's there a day and then you say, case be, uh, you list letter B and, uh, not gonna type all 26 of them. I'm just gonna basically say, um, diff another case. Okay. And ever gonna print your print that its letter. See? So and the default are we gonna print? It's some other winter that you don't? No. Yet. Okay, Um, all right, so there's some goofy stuff anyway, it's what happens. Basically, here is when you take ah, Swiss statement and actually compares the some character. And it seems like you know which block gold. Should I excuse? So let me actually come into school by here, so we see. Okay, um, when his ex it's gonna execute. It's gonna match the first condition, and it's gonna print that, Um, And when that is printed, it's gonna actually exit out off this office statement. So in other languages, if you if you might have noticed there's a break, Um, now that break is not applicable. In case off, Case and Gasol switch in left, um, sift does not allow followed through. It has a a fall through, and it has a keyboard called full. True that we're gonna take a look later on. But by default, basically, let's say if you wanna, um, combined two conditions, you can say a or B, for example, and, uh, safe Do a um, if you execute this, it should say, like, you know, it's gonna It's gonna complain about it because you cannot do this now lets me give you a quick run down. Now, this is a little bit like, you know, head off like, you know what we're discussing. We're going to discuss this a liberal, but I just wanted very like, you know, this is the way to actually do the fault. So you can say if this is case A of this case be then used to fall through. We really use it. I'm gonna explain you why, Um, like little on a little bit Because you're gonna see some some riel complex usage off switch within surfed that makes things whole thing going and makes it really, really easy. Okay. Anyways, um, your default statement is ah, basically there. If nothing matches, then you can print. Are you gonna execute that block off court? So if let's say we had, like, you know, e, for example right then it's gonna basically execute the default. Now, in case off switch, you need at least one case and default or a t least default. I mean, but it doesn't make sense to have a default on its own evidence, which, um So you have, like, you know, you can have at least one case and the default telling of the default block. Of course that you elected it. All right. So hope that is, that is clear implicitly. There is no fault through once one more time. It actually does not allow you to do that. Safe does not allow you to do that. And, uh, the way you can handle the situation is like this. Let me copy this, and I'm gonna based in right here. Okay? So you can compound these two, and this is called compound case, and you can say it's a or beat. Okay, So if I executed right now, that waas actually OK, the Vegas Gil. Right now it's actually going to execute this block off gold because it's matching this or this. There you go. And this actually eliminates the need off that, like, you know, fall through. I mean, in some cases, you might need that, but about like, you know, I mean, this is another way, if you're just looking for multiple value match and stuff like that. Okay, So that's the That's the only, like, you know, difference between these two. We can actually make it more compact and more concise. All right, let's take a look at another. Another statement. So I say this one is actually a little bit more complex where you can actually use interval matching, so you can define intervals and you can match those intervals. So, for example, let's say you had that Brox count, for example, and I say you have 62. Um, and you have counted. Thanks. And you have, like, you know, basically some value here. Okay? And you say let natural pound, for example, strings. Okay. And now I says something like, initial come something. We're gonna begin a store, but switch okay on our search takes approx count. OK, And now are our case is, for example, that could be zero. And we say natural count is equal to know. I mean, let me do something pretty simple. Actually, this is actually related to moon cycle instead. So moon orbiting Saturday. Okay, So how many moons are orbiting? Certain? None. So we say, No, there's no national account for that. And we say case, uh, between 12 four. So remember that has half close. Um, this is half close, um, range. And we say we say natural count. Uh, not natural. Count is equal to a few. Okay, So a few are basically, um, rotating. If it's 1 to 5. Case five, uh, two sn, 12. In that case, natural count is maybe several. Okay, Several ones are doing it, and then default is, for example, actual Count many. Okay. And we forgot that we can move that There's no double default. Okay, so in this case, how we can print, um What are natural count is going to be? Ah, for example, Right now it's 62. So if we execute, that is basically definitely going to fall under this default. But let's see if we do it too. See, like, they take a look. There's no to here. It's just range 1 to 5, which is going to for, um, and we say a few. And let's say if we do 55 because five is here and five years old, that's a bit honest us. Ah, that's interesting. Okay, because this is half open, like half open range Has you remember, it does not include the last rally. So, um, if you wanted to include five, that would have bean this case. But in that case, it's basically going to match first condition and just can exit up, even though the second condition is actually satisfying the same same pattern, but it's not gonna not gonna work out. OK, so let's change it back. Okay? So yeah, So that is your interval matching within switch now. Um, I see what else we have. We have two bulls. Okay? so we can use to both in search of all. So let's say we have some point in coordinate space and we have 11 We say switch some point is, for example, if it's 00 we print, it's the origin, all right, So instead of region and, for example, you do case efforts how we don't care about the 1st 1 But it said zero for the why, Then we print. It's on X Texas, okay. And if you take this same and we say if you don't care about why, access position. But if it's number in like you know, if it's X is zero, then it's somewhere on the Y axis, and, um, then we give it the last one. Which is, if it's basically negative, for example, to to negative too. Two big. Basically. This arranged to basically negative due to do on X axis and negative 2 to 2 on. Why access? Then it's somewhere somewhere inside. Okay. All right. So let's execute this. Help Mommy into the two point footprint. It's outside the box, for example. I mean, okay, so in this case is going to basically print it somewhere inside somewhere. Our earth inside the box. You have some highs. Hypothetical boxing. It's basically inside that at that point. Uh, now, if let's say if you say, if you make this year Oh, and they make it seven, basically, it is going to say it's on X axis, okay? And similarly, um, so that shows you like how you can basically do some a really complex, um, complex patterns in surfed for such statements. Have it. And why access? All right, so that was Teeples. Ah, and you can actually define You can actually create some complex solutions based on our people's case. Um OK, so well, you binding. So what is Ah, value binding? Well, you can have, ah, certain values, actually, and name them basically and create like, a variable outfit. So, for example, let ah point, for example, is equal to to end zero. Okay, Okay. You see, create a straight on this point and you say pattern is let X, for example, flipped X and the O. Okay. And you say, what do you want to do here? Is you wanna print, um, on X? We had value. Thanks. Okay. And you can similarly say if it's, um Why then, uh, you can actually print that with own? Why wait? Value. Why? Okay, and default is, uh oh, we can do last one we can do Case? Uh huh. Let X and y okay. And you can do print X. It's Xlu. And why, yes, my value and their default His default You, for example. Now let's execute this and you can notice. Then it says, like, you know, if it's like X axis and zero. So we actually gave it a Really what? It was all supplying. We actually got that. And we're wearable to print it, that is value binding. That is minding value that you have received during the during the pattern matching that you have actually defined. Okay, And this is a very simple use case, but in do some really, really, really, really cool things with it. All right. And this is another good example where default will never be executed because we're covering all the conditions of you really don't need default. So you don't need default all the time. And this is this is a particular a. So you saw You don't need it. And compiler tell. See you. So you can just remove it. All right. So let's see, like, you know, a simple case for where, um, so that, um you have, uh, point, for example. And one and one, for example. In negative one, maybe. And you create switch on point and you say let x ex And why Winner X is equal to why execute this code X and send why are equal. Okay, Otherwise, just print brand, not how simple case. So, if we execute that, you can say it's not equal because there is not going to execute. But if you say like, you know, if you make the point basically 11 where it actually satisfies that that condition, then you would say, uh uh, this is actually equal. And this is how you can create very can use their inside here. Ah, such statement. Okay. Um all right, um, this Let's see, compound case. We have already seen that. So we're gonna skip that part. Um and, uh, that's already already done. We have seen it, like, you know, right here, just to remind you guys right here, we have actually seen that for some reason, I had I have twice. Okay, continue All right. So continue is basically continuing from, like, you know, so continue is sort off, like control statements. So it's actually not not really part off conditional. It's so let me see. Control transfer statements. Okay. So I guess this is not really part of the, uh, the conditional. So let's cover it in the next video. Okay. Right. So this is it for the ah, like, now, for if a Nelson switch and all See you guys in next video, we'll talk about how control transfer statements, like continue break, fall through return and jacket be availability just because it doesn't have any home. We're gonna cover that in that video. Okay. Have you guys in there That's really also against bacteria? Thank you. 10. Control Transfer Statement: Hello and welcome back. And today we are going to be talking about a control transfer. Statements not controlled France for statements are basically used to change the order in which your code is executing. So, for example, let's say, um your running into a loop. And, uh, you, uh you checking for the condition, And if condition is not met, you don't execute further down in your block. What you want to is basically, you on a continuous loop from there and go to the next iteration. And that is like, you know, the control transfer statement where you actually break the natural course, and you actually transfer the execution to a different part. Okay, so, um, I think continue is one of the most common one that you're going to see and a break eso. So let's stop. But continue because that's going to give you a little bit more. Um, idea how how it works. Eso continue. Ah, statement what it does. Basically, it tells the loop to stop what is doing and start again from the beginning. So and when When it says start again from the beginning, it doesn't start from like the beginning. Beginning basically from the next situation. So let's say you're running a loop between 1 to 10 and you're at step five. Now, if you're continue if your coat encounters a continue statement, um is going to go straight to 66 step. Okay, so that's how continue actually helps. So let's, uh let's take a look. So, for example, maybe we can do is listless Run a, uh, this Ronnie simple. So I'm going to say for, um, I in vo two 20 And, uh, if I becomes, ah 10 whenever it becomes 10 and I is still less than 15 ar 15. Um, continue. Okay. Otherwise are just sprint I value if I so value off i IHS I think so. Okay, so basically again, back to our definition that we discuss the way continue work is, uh you run through your running through your loop and under certain conditions, you wanna check if those conditions are met or not met, for example, You want to say, like, you know, if you have not condition, basically like, you know, it's stuff like, you know, having a trouble nation. You have, like, you know, you're checking for something to be not true. And, uh, but that actually satisfies your conditional block. Then you going to continue. So you check for the condition, efforts satisfies you, go within the within the within if block and you do whatever you want to do. So I say, friend, No, we don't want to print anything. We just want to continue. So So I'm going to say continue. So continue. It's going to start back from here. It's going to basically say, OK, um, at 10. So I should go to 11. It's gonna come back here. It's still, um, now in this case, Um, OK, so it's, um it's bailed them equal to 10 in less than 15. That's actually the right conditions. Okay, so it's like, you know, it's 11 and still mused, Eso continue, continue, Continue. So it's kind. It's gonna print 10 on numbers. Let's make let's make it short. So let's make it like, you know, five in less than, um good night. Okay. Um OK, so that's the lesson in this cold and and take a look. So I didn't. Then we're gonna talk about it, so it's only gonna print 1234 and then it's gonna print. So 01234 Then it's gonna print nine and 10. Okay. So, see, like, how what happened to, like, the numbers in the middle? Basically, the continued block was executed, and it tells a told off loop that hate continue from the next iteration. And, ah, it's going to keep meeting this condition basically for the next few alterations. And basically, it's going to continue from next. And when it actually this condition satisfies false. We just like, you know, it doesn't satisfy any more than it's going to go to the next block. All right, so that is the, uh, the continue block. Okay, are her continue control transfer statement. Now, this is like one of the example. Another one is brake now. Brake statement. End the execution off entire control. So a statement immediately in break statement. So basically can be used in Fitch or in loops statements when you want to terminate the execution off, switch off or loop statement, um, earlier than what you were expecting. Okay, so in that case, you can actually use a break. All right, um, in at the way break, for example. Works is let's see you in case of switches to a simple So what do you say it like? You know, you have. You have a character. For example. Let's create a character char ah, and character. And this character is, Let's say G, for example. Okay. And you say switch. Uh uh. I'm going to say hr and one of Majesty's. So I'm going to say if it's, um, a Okay, um then print. Hey, could be and print be okay now in get off. Like, you know, if it's none of these, then your default block excuse. And this is there, you can actually put a brake statement. Now, what happens, basically estimates it encounters the break is immediately gonna, ah, like foot. But, I mean, default is anywhere is gonna executed at the end, but it's no longer going to continue if you have anything down here because it's never gonna get executed. Okay, so it's gonna the control is going to return from here. Okay, So in this case of weakness, notice that nothing is gonna get printed because our character is G and none of these blocks argon excuse. So if I had a eyes gonna basically print a. Otherwise, if I have anything like in other than A and B, it's just gonna not not execute the block. Okay, so that is a break in switch statement. And for example, in the four loop, you can say for I in house you to 10 and if I becomes five, I want to break this loop and go back and, uh, basically, otherwise, I want a print. I Okay, so let's take a look at this one. And, uh, look at this. So basically my condition was met and I executed break, which actually returned immediately, and it did not executed further. So that's why my loop was only executed five times and it had printed all these five values . OK, so that is a break, then. Next, we have ah, fall throughout the example of falter you've already seen basically, you use it with a statement where you have, like, you know, more than one condition to meet. So, for example, let's say you have ah number. For example. One are like number three, for example, and you say switch. Um, and I said number in case battle Is this that you met one now than you print one, uh, you pat match to or you match three. Now, in other programming language, other programming languages. This is actually true where you can actually put two cases, right? Uh, like, underneath each other. And that would actually just create a fall through. But in case of served, you have actually define it has fall through. And he's gonna say, You know more, Dan one and break out from the default. We just gonna break, okay? And if he executed right now, it's basically going to say more than one, because it just three. So it's gonna actually fall through for two and, uh, fall through and and three So this is how the fall through basically works is just combines . These two do our, like, hold on many conditions, so your condition match is gonna fault. So let's say officials to right here, then also is going to basically fall through and execute the next block until it actually meets that sound. That block that can be executed. So that is how power that's fall through. And ah, next one is a break. So sorry. Return. Okay, So return is return is basically a, uh an early exit so forever, for example, years use it a bit guard. We haven't actually explored guard, but the guard is like an reflects statement. So, for example, like, uh um let's say you have emotional while you So you had I, which is optional, and and we haven't talked about optional years, so just bear with me getting a little bit ahead. But, ah, short description is your values usually have values are making can hold 22 states basically has something it doesn't, um how now engaged off optional. It can also hold a nil. So there are three states. Ah, that's what optional actually provides are now in case or value types is actually a two state eso by default value type cannot be nil, which is, like, you know, value types are like, you know, primitive types indeed, your double throat and all these things they cannot be no usually, but with optional, they can be nil or can hold Hey, none or little value. Okay, so I see you had, like, you know, a very well. And so if you do if let, um uh, underscore, I I'm just gonna create another able and say I and, uh, print, I underscore. I actually health print none. For example, what this is going to do if there is a value in I it's basically going to get a sign into this new label and it's gonna get printed and we're done. Ah, this is optional by the way we're talking about. And if there is no other than it's actually going to go in the else block and it's gonna print none. So in this case is gonna print none right now because, as you can see, the value of Phi is now. But if we assign a value to, I is gonna print under skits and basically unwrap it with, uh by assigning it to a another way, Bo. And that's how it's basically gonna execute this block. Okay, so this is if let. But, ah, you can achieve the same thing with a statement calling card statements. So the way you write this guard and you say, Let underscore I, for example, and uh huh, If it doesn't meet, then you say print none, and you return directly from here and this is the early exit. So your condition did not meet, so you won't actually return our little return. And this is how basically it's gonna use. But it's not. It's not valid here because we're outside functions. Let's create a function so funk sample function, for example, and we just return here. Otherwise, we print value off. Underscore I Now what is the difference between garden f Let so the main difference between guard and the flat is when you when you're fine, I to this underscore. I, um it's only available within this block. So if I try to exodus underscore I outside, I won't be able to access because it doesn't exist there. Now, that is the main difference between if a if lead and guard basically guard what it does, it creates a, uh, like, you know, from the point of execution onwards, a create stack variable and put it in the memory. So that's why are you on outside the bloc here? We were able to access underscore I Okay, so let's calm it this cold. And I want to show you how or what? Basically, Iskan getting executed. I don't actually believe this. And sample sample. Oh, sound confection. Okay, so right now it's actually zero, So that's why it's actually printing it. What if we say no? If we say like, nice nil, it's basically a just returned from here. And as you can see, our next line did not even X. That is called in an early exit. Okay, where If your condition is did not meet you on exit out of that function because, you know not like, you know, execute those two you're depend upon, like some of the some of the values to be available before you actually can continue for the wrong. So that is where mostly returning used and returns also used to return something in the function that we can actually explore in the Functions section. Okay, let's talk about the last stopping of the day. And that is now checking a p I availability. Okay, so sift has ah basic building. Ah, checking for a P. I feel guilty if that if that FBI is available with in the current version or the version particular version that you're looking for off sift or Iowa's basically it's many for Iris . So we can do is ah, the stuff you're using some functionality and you want to make sure like you know that it, uh, execute you want to say, like, you know that it only available offer I stand and above the best example, I can think I can think of his like, let's say, if you're doing something with normal, um and, uh, you and actually put that like, you know, because Coronel is part off for a meal is actually better, but yeah, Gorham L Because it needs the framework. But a steak or a male had some functionality that was introduced this year, like, and I was stole. And, um, how you're still like, you know, when I stroll in your developing and you and actually provide back, back backwards supporters all, um So in those cases, you can actually provide this FBI availability So you can say if hash available and you can define the platform here so you can say IOS and you can define the version here. So I was 10 and you can say, like, you know, call my basically for Mac. So if you want to say, like, you know, Mac or other origins, basically, So, um, toward the Swedes, it's a youth. I was standing ps on IOS and use any other FBI's own other platforms. For example, Mac, like, you know, whatever version you can use, or you can actually define back Y So So he can say Mac OS 10 that role. Come on, Star. So it's only gonna execute for those conditions. And if this condition is not met, basically the FBI is not available or for these versions, then execute whatever is in the else statement. Okay, so that is FBI availability Check. Uh, it does not fall between for then, you know, I mean, a sort of falls within our control transfer statements because it also of transforms your control. But it's more like checking the availability, which is, uh, going to be useful for Leslie push notification stuff because push notification has been around, like, you know, for many, many years. Um, and, uh, there are some recent new Fortunati that are available, and that's actually another thing. And this is another function that it can be used to make sure that those, uh, those new from shanties or new matters don't like it executed when you have, like, you know, worsen more than what it's actually supports. Otherwise, eyes can actually throw in there but one. The good news is, um, uh, when you actually create how you create a function call which is available only like this day I was standing above and your target for the app is I was eight then your compiler, Circumpolar or xcor propeller. It's going to basically give you a warning saying, Hey, you're using something that's not compatible with older versions that you wanna create the availability check on, and it will actually create it for you and all you need to do this. Put the like the backup like, you know, functionality that you won't fall. I get her. Ah, check through. So follow through from Channel two. You actually write it over there. So that's it for the studio. And ah ah will see you guys in next video with some something about functions. And we can explore ah, whole lot about how to create functions and, like, you know, some other things that he can do with functions and stuff. Okay, thanks again. And I'll see you next week.