Transcripts
1. Optionals in Swift 3.0: Hello, everyone. Andi. In this video, we will learn about and important functionally the witches and swift, which is scoreless optionals. So basically, optionals can be created for in teachers. Double strings and any kind of data time gratis provide evidence of tree. So the main question guns is what is an optional so obstinately basically mean that it can either have a value or not. So let's say that we are downloading some data from Internet, so they're possibilities that the downward will complete and Donald will not. So, basically, let's say we have a variable which is storing the data, which is coming from the Internet. So suppose there are only two conditions that the download will complete, and it will store it in the variable, and the downward will not complete. So basically, for that we can use optionals, so if they download is complete, the value will be assigned. And if the Down Lord is not complete than it will have an value called nil. This is the functionality, which is only provided in the programming language. So let's see optional in action. Um, so let's say let's see first how we can create an optional notice the variable off type age , hundreds of type and, uh, and we wanted to be an optional. I suggest we have to use this and Dan so large that we're doing all the things are similar . Only we are using an exclamation mark at the end toe. They know that this is an optional conserved. So now if you tried toe bring age. Let's see what happens. It's running, it's running. You can see that we have got an adder because the optional is nil. So that's said some value. Let's say 25 I'll print it again. You can see that it is sprinting 25. So there is a method for optional to print so that our program will not crash and it is in simple method. So let's say I have an optional called name off type string, and I shined a name called Summer Proble. So this is a new construct in swift three If Lex name be clear to name Green name as brain . No. Well, you found. So basically what we are doing is we are creating an reflect construct. It is basically used when we are dealing with optionals. So we can do it name equal to name. So what we're doing is if name has some value, then it will print it. Otherwise it will say no value forward. So suppose that our optional has no value, so you can see that now. Our program will not crash because we have used and deflect construct and it will paint know where you found. We can also do the same for age. If let age speaker toe age, I began to print age on. Begin to Al's we can bring to gain and see age is still on de fined. Suppose that we have no defined age. Let's define name so you can see that for ages sprinting that the age is not to find And it will print the name because we have initialized the value of name to be so much problem. So basically there isn't another mattered for creating an optional which is like this valuable number of dive double. And instead of exclamation mark, we can use a question mark. So the basic difference between an exclamation mark and question mark is that if he had using question mark, then we have toe on, grabbed optional while printing the value and Wi Fi have used exclamation mark. Then we don't have to unwrap the option. So let's see the question mark. Optional in action that Syria sign number equal toe 10.25 Knowledge fee brain number. Let's see what happens. So we have plenty number. So in the output you will see something strange. Okay, so you can see that's an output. And instead of printing number, we're seeing something like this optional 10.25 This is because whenever you are declaring an optional with a question mark, you have tow unwrap the value while painting it so for unwrapping and we have to use the actual emission mark. So let's put exclamation mark and now you will see the output that it is. Dan blamed Duel So basically this is two different types off optionals. Not too different tapes. Two different types of declaring an optional instead of tree. So I will always prefer to use the 1st 1 because it is easy and you don't have to unwrap the option value. So this was about optionals and swift, and when important thing is that optional is very our topic for big nurse. So those who are facing problems and have not understood it completely well so please group So please google it and you will find many different links. So please go through it. And you will definitely understand what is an optional Thank you for watching this video.
2. Calculator Task: Hello everyone, welcome back to the scores, and in this video I will give you a task on In the starts. You will have to build a simply calculator, which will have four different functions. Addition, subtraction, multiplication and division. So the function will look like this. The name of the function should be calculator calculator, and it should take three different arguments. The 1st 1 is operator, the second is first argument, and the third is second argument. So operator, therefore, choices available for operator the 1st 1 is a for addition. As for subtraction and formal dip, elation and D for division. So for let's example, I've president argument called a, which means a four addition. No, I have Dubai's. My first operation selects its 10 and now I have to give my second or print. So let's say is 20. So now this function will automatically calculate result, and it will show you to you. So as you can see that in the console below, you can see that addition is 30. It has used addition because we have provided the argument called a so supposed that we want toe multiply two numbers so we will use the same function calculator and the argument we would be am because for it is a lot of manipulation. Let's say first number is nine and second number is 20. So let's see whether the answer is when it er not. So now you can see decked. It has successfully Evan. And here you can see that the multi predation is 1 80 So let's now try for subtraction as well as the reason for subjection. It should be s and lets a breaks 20 and 10. And now let's try Division Onda argument for Do you division would be D. The first argument is 100 and let's seed. Ah, a second argument this 20 Let's see whether it's looking on art. Okay, so here you can see that and output subtraction off. Wendy, Minister, I understand. And the region off 100 divided. Where to India's five. So this is ah, simple task for you. So please try to make this calculator. And in the next video, I will myself scored this whole Cal greater and I will show it to you. Thanks for watching this video.
3. Calculator Task Solution: welcome back to the scores on as you know that in the last video, I gave you a simple tasks to create and kill calculator. So if some of you have completed their task and it's very good and if you have failed, if you have feels any problem, then in this video I will go the calculator myself. So let's start. According so First I will create a function, which is the name called Calculator On. It will take two different arguments. The first is the operator, which is with Type String and the second argument, which is off type double and a toad argument, which is also off type double. So basically, this operator will tell us whether we want to multiply, subtract or divide two different numbers, and this is the first number, and this is the This is the second number. So now let's light the function body. So inside the function what it will do, we will use if else, which is the conditional logic in served programming language. So what I would lose if o P is equal toe, let's say at Fort Edition it should be a oh O P equal equal to capitally because the user again bars small or capital a boat. Then this is the first condition else If now it will have the second condition. Oh, peak. Illegal to let's say for sup election, it should be s or Pekar Do Capital s now the third else of condition. Hope equal toe. Let's now do former depopulation. Now we will have the fourth condition ritual before division. We live the last condition in which, if suppose, a user have provided some wrong argumentative and begins to an air. So we will bring Please provide. Operator, this is an Adam. Okay, so now let's scored. I was first condition. So inside this view or what we have to do is if disconnection is true, it means we have to add two different numbers. So let answer equal do first plus second. And then we can print addition and by a string interpolation, we can bring the answer. No. Similarly will called, uh, second LD condition. If this is true, it means we have to subtract two different number so we can tow first minus second. And now we can print the result using the same above Mattered directly have used now a string interpolation we will print. Answer Now, let's scored a turban. So if Orpik will, um, it means we have to multiply two different numbers. So the procedure is basically seem we only have two use different symbols just was a toward condition. Now let's do it for four condition. So in this, if pope equal to be, it means we have to divide both numbers and then we have to print it using a simple print statement. So as you can see that we have completely quoted our calculator, which has four different functions addition, subtraction in the region and multiple elation. So now let's see that the dysfunction is working correctly or not. So let's try for Ford all four different functions. First, we will look addition off two different numbers. We will call the function calculator less Pass A. The first number stand in the second number is 20. Let's see whether it's looking or not. Here, you can see that we have got the output. Tradition thought it means addition, is working. Fine knowledge strive voice subtraction. Let's say 100. Now let's say 200. That's easy. The answer. We should get okay So now you can see that it is get giving us minus 100. It means it is also working directly. Now let's try for multiplication. That's try 10.25 and to 5.25 So let's see the our Produce 53.85 I think it's hard to calculate so we can cross checked on gig on Google if you want about. Yes, the multiplication would be correct. Knowledge. Try for division, so the argument would be small. Your capitally. Let's divide 100 by 20 and let's see what is the output So you can see that the division is five, which is correct. So it means our calculator is working correctly. So there's a lot of basic simple calculator using Swift Tree. And now, from the next video, we will start by learning some aspect. Soft developing iris applications. See you in the next video