Objective C Tutorial

hello internet and welcome to my objective-c tutorial in this one tutorial I’m going to teach pretty much everything you’d like to know about objective-c and also as a side effect I’m also going to teach a lot about how to program in C because they are quite similar I’m going to be programming using Xcode but for the Windows users out there I’ll also show you exactly what programs you need to run this code because it will run on a Macintosh Linux or on a Windows machine so I have a lot to do so let’s get into it okay so for those people that are on Windows this is what I suggest if you want to be able to compile objective-c programs you would either use Ming w org and download mingw or go to cygwin comm and download this and you’ll be able to compile all of the objective-c programs that I have here in this tutorial now let’s jump over and start writing some code no like I said I’m going to be using Xcode here but I’m also going to be using the terminal or command line to show you how to execute those and I just opened up Xcode and I’m just going to click on OSX application and command line tool and click on next I need to give this a name I am going to call this objective-c Tut for tutorial I’m going to leave Derrick baƱos in there and then here you’re going to put a unique thing so I just put my website backwards and I’m going to start off actually by writing a C program and I’m going to work my way towards Objective C I’m gonna click on next and it’s going to say where do you want to save this I’m going to say that’s perfectly fine and I’m going to open that up and whenever you open up your file inside of Xcode you’re going to see all this stuff what we want to do is we want to come over here on the left side of the screen and specifically open up main dot C that is going to be where your code is going to execute and like I said this is a C program right now now basically like I said the code in the main function right here is what is going to be executed any time you run your program and if you’re wondering what these attributes are right here whenever you would run your application from the command line or the terminal you would be able to pass in the number of words being passed into this function as well a list of those words inside them in array and I’ll demonstrate that here in a second but first let’s focus in on exactly what printf is you’ve probably seen this before basically all print is going to do is it’s going to print whatever words you have inside of these double quotes and then the backslash n is for a newline which just means skip to the next line let’s come in here and let’s use the array that could be potentially passed inside here just see how that works or what the heck let’s just run it and see what happens so you can see here I just ran it and HelloWorld shows up down there so that’s all printf does it just prints out whatever you have here on our screen let’s delete this and let’s do something a little bit more advanced for looping I’m sure you’re aware we’re very often going to use for loops and they are structured inside of C and Objective C in exactly the same way first we’re going to initialize a variable and let’s just have it be I is equal to zero and this guy right here is going to change in some way as the for loop loops and performs actions that you see right here over and over and over again as long as this condition right here remains true so I’m going to say they want to continue looping and we’re increasing the value of I as long as I has a value that is less than argc this guy right here whenever we pass an array which is just a bunch of boxes that contain values into the main function what this is going to do is to allow us to iterate through all those different things so if you send in a sentence that was something like I am happy I am and happy would all go into different boxes inside of an array and they would have a label or index of 0 for I 1 4 a.m. and 2 for happy and it’s probably better just to look at this or if you have programmed you’ve seen this already before and this is just shorthand notation right here for increase the value of I by 1 that’s all that means so we’re going to do is cycle through this array and I’m going to use print F here again and I’m going to say Arg and this is going to be the argument type that we are increasing right here and I’m going to put a percent sign followed by D which means that we’re going to be placing inside of there an integer or a value that does a decimal place and a % in an S which means I’m going to be passing in a string and then a new line which means I want to skip to the next line after it does that here I’m going to then send the value for I and put it right here and then I’m going to get the value for our array that’s passed inside here and put an eye there and remember like I said everything’s going to start off with a zero n n increase a zero one two three as you’re going to see here in a moment now I’m going to use the command line on purpose just to execute this and I opened up my terminal or command line and I change the directory to where I have all of these files listed and I’m going to show them all right here you can see objective-c Tut that’s the name of the project I created so let’s just jump inside of there and then you can

see the main dot C file which is the name of the file that’s over here on the left side of the screen now if I want to compile this program I’m just going to go GCC main dot C and you’re going to do this on Windows as well and I’m going to type in standard is equal to C 99 and now if we hit LS we’re going to see a dot out is there and that is the guy that we want to execute and to execute that we’re just going to then go dot forward slash a dot out and then followed by whatever you want your string to be to pass inside of there and here you can see there is the command passed in here to this array as well as each of these string values also passed into the array and you can also see the indexes that those are all passed into just wanted to cover exactly what all this stuff means you’re not going to use it very often but now you know as well as you have an overview of exactly what for loops look like and what printf does but we’re going to get more into that later if you use an objective-c and you want to get rid of this bar over here which we’re not going to be using that much you can just click on this little guy there and that’ll go away and likewise if you do not want the debug area over here you could come over here and click on this guy and that’ll go away as well and then we’ll just have our output from our application that’s running here on the screen didn’t mention it here but this includes statement is just going to include a whole bunch of functions that we’ll be able to use functions like printf to be able to do all sorts of other different things which will demonstrate here as we go on and now I’ll jump into the different variable types that we’ll be able to use to store data now basically there’s a ton of them we have short and I’m going to also say exactly what we’re going have to use here if we want to transport a value stored in this variable over inside of here inside of the string to be printed out and in that situation it’s going to be % day just like we had before likewise you’re also going to use % D with integers and with Long’s we’re going to be using % LD floats or values that have a % are going to use % F doubles which are just like floats except they’re quite large are going to be using L F then you have characters which we’re not going to be using that much but if you ever feel the need we’re just going to use descent sign see there’s a couple other different datatypes but we’re going to focus in here on strux as well as pointers as the tutorial continues and a struct is just a custom data type which is better to understand once you see it and a pointer is going to hold the location of data somewhere inside of your memory so what we’re going to do right now is I’m just going to bounce around and create all kinds of different things I’m going to start off by creating a float and let’s call this F temp and whenever you’re defining the names for your variables we usually use camel casing which just means the lowercase letter followed by an upper case for each individual word you want to focus in on for your variables such as creating a data space for me to be able to store information now I’m going to use printf again and this time I’m going to allow the user to enter information so I’m going to say enter temp in Fahrenheit and we always want to put a semicolon here at the end of our statements now if I want to get information from my user I could use scanf and what i’m going to do here is I’m going to define exactly what datatype I expect which is going to be a float that’s what’s going to be sent to the user and then we’re going to put and f10 and we’re going to get more into what the and part is in a little bit but for now just put and and a half temp whatever the variable is now what we’ll be able to do is create another float and this is going to be C temp which is going to represent Celsius here I’m going to perform a little bit of math I’m going to say I’m going to want to get the Fahrenheit temperature and subtract 32 from it and divide by 1.8 and that is how we perform subtraction as well as division and now after I created that I could then go printf to find exactly what I want to put here I want to put a float and let’s just say i1 one decimal maximum after that float I’m going to put the F right there and degrees Celsius and we’ll throw in a new line as well and then after that of course we have to say what we want to the value of the variable we want to put right there and that’s going to be C temp and if we execute that you’re going to see down here it says enter temp for Fahrenheit and let’s just say I say 70 degrees it’s going to Chuck back 21 point one degrees is what that would be in Celsius something that’s also useful to know is exactly how big of numbers we can store in these guys basically whenever we say something has a datatype what we’re really saying is hey computer I want you to set aside a certain amount of memory which we have a limited amount of for the data type that I want to store there now the biggest integer that we could possibly store and let’s just call this big int is two one four seven four eight three six four seven and what we’re going to do is we’re going to prove that that is the biggest integer that we could possibly store and we’re going to put in an integer is what we want to store there then we’re going to get big int and add one to it well you’re going to get a negative number and this by the way is the absolute smallest number you can store in an integer so just be aware that there are size constraints in regards to how large of the different data types we’re going to be able to store now along is also a whole number type however we’re going to

be able to make much larger Long’s as you can see right there that’s the largest long we could possibly create and if we want to save that and we want to execute this you’re also going to see that that gives you a negative number and that is the absolute smallest big long that we’d be able to use so pretty much every data type in one way or another is going to have limitations but there’s outside libraries we can use whenever we want to be able to work with bigger numbers like that if we want to be able to find out the absolute minimum float that we could possibly work with you come in here and let’s put a cent sign and E and there’s actually a constant that is going to tell us exactly what the minimum float is there’s also a constant to show us what the maximum float is and we can execute that but as you see right there it actually says undeclared identifier what are we going to do what that basically just means we need to include another library and in this situation we want to use the math library and we’re also going to want to use a float library now if we run that you can see right here both the most negative of floats that we could create in our system as well as the highest possible positive value we could store of course those are also going to be decimal places however it’s very important to know that whenever we’re using floats or doubles that they lose precision after six digits and we just come in here and demonstrate that so let’s say I go and create a float give it the value of pi and then we’ll go point and we’ll go one two three one two three and then a one remember it only has precision up to six digits and then we can come in here and try to print out seven digits of accuracy and then go PI plus in actuality we could also have the computer tell us straight off how accurate is how many digits so we’ll say precise decimal digits and have that print out as well and remember this is a C program but like I said anything that’s done in C we could also do an objective-c and if we run that you see right there one four one five nine two six this is one four one five nine two six even though we went in there and added an additional digit it completely ignored it you can see right here precise decimal digits goes up to six so now that we spend a lot of time on different variable types let’s get into comparisons and being able to perform different actions depending upon a situation so let’s create an integer here equal to age and that would be 13 I’m going to put we can use an if statement that’s going to say if the age is less than or equal to 6 in this situation then and say something like you are in kindergarten like most other programming languages we’re also going to be able to come in here and go else if and put in another condition let’s say age is less than or equal to 13 and then finally as the final condition we could say something like you’re in high school and there we go and if we execute that you’re going to see you’re in elementary shows up here and the reason why is this is equal to 13 so if Sande else’s and elf if statements work in C as well as Objective C in pretty much the same way as other programming line images and the different comparison operators this is a comparison operators that are going to be available to us are also very similar to other languages we’re going to have less than greater than less than or equal to greater than or equal to equal to and not equal to so there’s all the comparison operators so what do we have in regards to logical operators well logical operators are basically going to allow us to combine comparison operators and we have and we have or and we have not it’s better to come in here and just demonstrate what those look like so we could do something like if and we could say age is greater than or equal to 12 or age is less than or equal to 13 we could then print out something if that indeed is true which in this situation it is and it prints out you’re in elementary right there basically what this is saying here is when we were used thus illogical operator or if this is true or if this is true then I want you to perform whatever is inside of there if on the other hand we decided to use the and logical operator we come in here and create a boolean for example now let’s go and import something up here standard full create a boolean type I’m going to say is elementary let me go equals and throw in the same statement we have before but in this situation we’re going to have and and what that’s going to say is this is going to get a value of 1 or true if age is indeed greater than or equal to 12 and age is going to be less than or equal to 12 if this isn’t true and this isn’t true then we’re going to get a false or a value of 0 and a boolean is it going to represent true or false or it’s going to represent 0 or 1 just like I said before so in this situation I mean here do another for an F statement put a D inside of there because it’s going to give us zeros or ones like I said before and then is elementary and you can see indeed is an elementary and it comes back with one or a value of true then finally to cover the last logical

operator we have the knot statement all the knot statements going to do is it’s going to turn truths in two falses and falses integers or zeros and ones and ones into zeroes and then we could do something like not and yes indeed we could use true here if we execute you’re going to say it turned the treu into a zero so those are all the different logical operators another thing that we have here for performing comparisons is the ternary operator so let’s go and create another boolean we’ll say something like is High School like this and what the ternary operator is going to do is it’s going to assign a value depending upon the comparison so I’m going to say if the age is greater than 13 then I want you to assign a value of 1 2 is high school so it’s pretty much used in comparisons in which you’re going to have either or come true otherwise if this comparison is not true we want to assign the value of 0 to is high school save it and run it and you’re going to see is in high school comes back as 0 another thing to keep in mind is when we are using if statements if you would come in here and create an integer called J and give it a value of 10 or whatever this guy right here is not going to be available outside of here and we could prove that right now like this and execute it and it’s going to say build failed and that just means if a variable is created inside of an if statement and later on if it is created inside of a function that does not mean it is going to be available outside of said function or if statements or for loops or wild loops which we’re going to get into more here in a second now let’s come in here and take a look at some things we can do with math basically what we’re going to be able to do is perform addition subtraction multiplication division as well as modulus which is actually done this way however if you would whatever want to put a percent sign inside of here inside of printf you would just double it up just like I did right there if we execute that you’re going to see exactly how those work exactly like you thought and if you don’t know what modulus is it’s just going to return whatever the value is of the remainder after a division another thing you need to do here is cast and that just means to convert from one data type into another so let’s say we go prune up and we want to get 3/2 is equal to and we want to float in this situation we could do so and here what we’re going to do is we’re going to say 3 divided by and if we want to cast the 2 into a float you just put this inside of here if you wanted to convert a float into an integer you would inside of there instead and you can see right there now it’s going to be able to put in the decimal places and I covered this before but if you wanted to shrink that down to only show two decimal places just point point two inside of there you’re going to say that it goes and only shows two decimal places instead of as many as it feels like showing I think it’s important here is order of operations so let’s say that we go print out and we’ll be able to see that if we go two plus one times three is equal to that is going to give us a different value then if we used brackets inside of here paste that in there except in this situation we’re going to put these brackets around here and what that’s going to allow us to do is to perform the addition first and then the multiplication thereafter you can see exactly how that works whenever we put the brackets around it it’s going to add this first and then perform the multiplication otherwise it’s going to perform the multiplication first and then add 2 to it another thing it’s important to understand is shorthand notation that is available so let’s create an integer give it a value of 0 if we would then come in here and say something like I plus plus is equal to and then put that in there for the integer what this is going to do is it’s actually going to first get the value of I currently and place that right here and then it’s going to perform the addition afterwards otherwise if we would instead put the plus plus right here it’s going to form the addition first and then after do nothing so save that run it and you can see that’s exactly what it did went through here printed the first value of I then added one then came down here added one and then printed the value out on the screen so there’s little things like that can really hang you up another thing to know is there’s also there’s all kinds of shorthand notation we also be able to go i plus equal to and let’s say 5 what this is going to allow us to do is add 5 to whatever the value of I is so we’ll go I plus equal to 5 run that and you can see that it printed out right there because it has a value of 0 and there’s also going to be shorthand notation that’s going to allow us to go i minus equal to 5 or whatever it’s going to be and we’re also to do that with multiplication as well as division now I could go into all the different math functions that are available but that would take forever basically we’re going to have ceiling as you can see right there which is going to deal with rounding upwards floor which is going to deal with rounding downwards you’re going to have absolute values square root exponents I mean there’s there’s tons of different things

that are available to you logs and powers I’ll just let it to you to go and explore the different math library and all the different things that are available for you right there okay so now let’s take another look at looping now we already talked about the for loop and you can see we’re just going to initialize a variable give it a starting value and this guy what it’s going to do is it’s going to print out odd numbers from zero to not so we just throw in our condition once again and that’s going to be ten and we’re going to increment it again using shorthand notation like before and then down inside of here there’s a couple other little key words we can use here’s our if statement and we’re going to say in this if statement if I ever reaches the value of nine what we want to do is jump out of the loop all together how could we do that we would just throw a break inside there so that’s one thing what’s commonly used with loops another thing let’s say that we also if we ever get to the point where I is equal to seven and we want to skip printing seven it’s quite easy we would just type continue and won’t continue does is jumps back up to the top of the for loop and continues going of course this is going to be incremented however and then if we just want to print out odd numbers we could say something like if I and then use the modulus statement with two which is if it’s an even number is going to give me a value of zero and if it’s an odd number it’s going to give me something other than zero which means we’re going to be printing out all of our odd numbers in that situation I’m going to go I and then I’ll go and print out the number so there we are and then throw our integer on there at the end and if we run that you’re going to say that it prints out one three and five it doesn’t print out seven because whenever it hit this point it continued never got down to this point and then prints out five and it never prints out 9 because 9 jumps is completely out of the loop so that is how we’re going to be able to use for loops now of course there’s also Wiles as well as do-while loops with a while loop you’re normally going to create a variable outside of the app the actual looping structure let’s just call it J and in this situation when you say wow J is less than or equal to 10 and we’ll say print out and we’ll just say J and pronounce the integer in this situation there that there and then another thing that’s common with while loops is we’re going to increment our variable inside of the while loop itself and if we run that you’re going to see that it’s going to succeed and it’s going to print out 1 2 3 4 all the way through 10 then we have the do-while loop which gets a lot of hate for some unknown reason what a do while loop does that’s different than a while loop is you can guarantee that it’s going to loop at least one time every time you use a do-while loop because it loops through whenever we say pin do and then it checks the while part of it so we’ll say wow and let’s create something let’s do like a guessing game or something so let’s say int and guess like this come down here and we’re going to say that we’re going to continue looping through this as long as the guess is not equal to 15 so we can go inside of here and then inside of this guy we could say something like printf and guess between 0 and 20 so we’re going to say guess a number between 0 and 20 and then we’re going to store whatever they put inside of there inside of scanf so you say D that’s we’re expecting an integer in this situation going to put and inside of here you’re going to see here in a moment why that is needed and then whenever we run that guy you can say guess between 0 and 24 take then 1 it’s going to ask us again 4 and then if we type in 15 then it’s going to end so there’s an example of a do-while loop that brings us to functions what I’m going to do here is I’m going to jump up here outside of the main air and this is where I’m going to be creating all my functions and basically how why we would use functions is it’s going to allow us to both reuse as well as better organize our code while I’m up here I might as well also talk about global variables a global variable is going to be able to be accessible meaning its value is going to be accessible in every single function that is inside of your file and how you create one is let’s say I have pi value so if we have functions up here outside of main as well as inside of main we’re going to be able to access all of those or access all of those and another type of version of this is what we would call a static variable and a static variable will only be accessible by functions inside of this file because otherwise we could have Global’s that also would be accessible from outside of it just by including them like we included here as you can see let’s create a function so I’m going to say first void what void means is it doesn’t return anything after the application or after the function executes we’re going to be getting a string here so we’re going to be using character star name once again I’ll show you what that means here in a

second we’re using pointers and here we have height and then we’re going to have another float which is weight these are going to be values they’re going to be passed inside air we’re going to be getting names heights and weights all passed inside of here and then inside of this function we’re going to do something with these guys what we’re going to do in this situation is we’re going to get the height that they passed in multiply that times 12 and then multiply that times 2.54 which is going to get us our height in centimeters and I’m just making up stuff to do here so we could also convert our weight to kilograms by multiplying that times 0.45 3 5 9 2 and then we can come in here and say printf and get it the name that was passed inside of here centimeters tall and way is and have two centimeters for that kilograms and then we can just throw in the name the new height as well as the weight and now that we have our function defined we can just call it and convert data and we could pass in Derek for example or why don’t we go and do this because I want to show you something else name is equal to dark and then we’ll pass in name here and then for our height we can say six point two five and then for our weight we could say 179 and if you save that and execute it you’re going to see down here it goes and prints all that information out and does all those conversions one thing it’s very important to understand is if we would come in here and say something like R and F and then try to print out our height which we defined inside of our function up above so here’s height right here and here is height right there but height is not down here and as you can see it has an error and if we click on it it’s going to say use of undeclared identifier height anything is declared in a function or an if statement or for loop cannot be accessed from outside of it and another thing that’s important to understand is let’s say we came up here and said name is equal to fill and then we came down here so up there we change the name to fill from Derrick we wouldn’t then be able to come in here and say name and main yes or we’d be able to do this is just not going to give us the result that maybe we expect so if we execute that you’re going to say that Derrick shows up even though Phil supposedly was changed up inside of here and the reason why is what if we pass these values up here we’re not passing the actual variable we’re just passing a value and right after I demonstrate our next function we’re going to create that’s going to allow us to return values versus void which doesn’t allow us to return them I’m going to come in here and I’m going to create a new function that’s going to return a float it’s going to receive a float and two floats and then it’s going to return none one plus num2 and we’ll be able to come down here throw printf inside of here once again and we could say something like five plus six is equal to and point one get our float and a newline and of course we could call the sum function pass that in there and it’s going to return a value just like we expected it would there you see five plus six is equal to eleven so now let’s talk about pointers now data like I said before is going to be stored in memory at an address and memory is just like a bunch of boxes and the data type that you define for those boxes is pretty much going to define how many boxes you’re going to need so if it’s a data type that is expected to be large then you might use a long or something along those lines however if it’s supposed to be really tiny might use a short or even an integer so what we’re going to do is we’re just going to start off here and dig more into pointers so let’s create an INT and let’s just call it random numb and give it a random value now if we want to come in here and get the address location for it just go ran numb location we’re going to be able to by putting P inside of here for a pointer and then to get it we have to go and random number that’s where that and is so this guy right here is going to return the address in memory for this variable right here execute it and you can see there it is a hexadecimal number and why that’s going to be valuable as we’re going to be able to store these addresses and so forth and pass them in functions if we would want to come in here and store a address we’re going to both or first off we’re going to use the same data type or whatever we’re going to be storing and then we’re going to follow that up with star ad or random num and then get the address for random num right like that so that’s important to know if you want to store an address make sure the data types are the same and then put a star before it or like that pointers are nowhere near as complicated as they seem it’s just addresses and passing addresses and then getting access to data inside of those addresses we could then come in and store a new value in that address by referring to star ad our random number 5 4 3 2 1 for example and we just copy this to save a little bit of time random number value and then like this and then

change that to an integer run it and you see right there 5 4 3 2 1 is showing up right there so if you want to store the address for a variable you start off with and and whatever you want store inside of there so this is the address of that if you want to change the value then if you have the address you proceed it with a star and then store the new value inside of there something else that might be interesting is even though we change the value the memory address itself is still going to remain the same so we can say random number memory location for example and in memory location we’re going to be getting a pointer and then put the + symbol here of course if we run that you’re going to see that yes indeed the memory address is exactly the same as it was before ff7 AC trust me it’s the same thing even though we change the value and if we wanted to we could also come in here and get the total number of bytes for our integer in this situation so random number is and to do that you go % + Z u and we’ll get the bytes for that and to get it you go size of and then pass in whatever the random number is or whatever the variable is you want to check you can see here that that is 4 bytes now something that’s really neat is previously we’re sending by value to functions what if we want to do instead send the actual variable and then you would be able to change the value there and then it would also stay true inside of the main function so let’s go and create an integer called number 2 3 4 5 and we’re going to create a function called change number just to prove that this works now to pass the address we’re going to go and and then number right like that and then after we do that we’re going to verify that the number value that we changed inside of the change number function which we’re going to create here in a second is going to remain the same outside of here now what we’ll do is come up here and actually create that function it’s called change number oops inside of here outside of the main function and this isn’t going to return anything so we’ll have it be void then I’ll have change number now if you’re going to be sent an address for a variable you’re going to put the star inside of here instead I’m just going to call it number again have to be but that’s what’s going to be here and then to change the value of the address that was passed inside of here we’re going to put the star in front of number and call it 97 whatever so they’re changed there so what we’re going to do just to verify we’re going to give number the value of one two three four five we’re then going to say that we want to change it and then we’re going to verify that it was indeed change and if we execute you can see that nine eight seven six five was indeed changed and it changed inside of main because we passed the memory address and not a value something else that’s really interesting inside of C and Objective C is we’re going to be able to create struck switch I talked about before it’s basically going to allow you to create a custom variable with more than one data type so let’s say we wanted to create a struct and let’s call it superhero we could then define the name so we’ll say real name like those and then another string inside of here and as you can see that’s what these are these are character arrays and they’re using pointers as well for wondering why they had stars inside of them and we don’t you know wouldn’t only store strings inside of them we could store Heights and we could store weight just make sure that you end up with a semicolon we would be able to come in and use this struct the super-heroes struct and let’s call it Superman and we’d be able to assign values very often like you might feel is normal with dealing with objects so real name just make sure it’s the same thing like we have right there and Superman again equal to Superman Superman again and we could assign his height and Superman weight and that if we would want to come in and use all of that data we just assigned we could then come in and say there’s a string we want to put is the hero feet tall and weighs % pounds and then if we wanted to get the values that are inside of there it’s easy we just go Superman dot real name and Superman super name height weight execute that and call Kent is the hero named Superman he is six point two five feet tall and weighs 235 pounds so that is the gist of Si and all of the comparisons between C and Objective C now what I’m going to do is focus in 100% on Objective C and talk a lot about objects and all of the different functions available only with Objective C okay so I’m back inside of Xcode and this time I’m going to create an objective-c application so we’re just going to go application command line tool again is going to work perfectly fine and we’re going to go next this time we’ll change this to Objective C and I’ll call this effective C type two and again just whatever your name is and some unique identifiers click Next where you want to store it and there you

can see everything opens up let’s get rid of this for now we are going to talk about that in a moment and you can see here once again we have what is called dot M file is also also referred to as an implementation file so there we go but this is the main part of our objective-c application now the foundation part this import up here is known as the foundation framework and it’s going to contain many fundamental classes you’re going to use your Objective C programs and of course we’re going to be importing a whole bunch of other classes in here real soon see down here there’s main again and we can get rid of this stuff right here I’m going to talk about NS log and how it differs from print F but first off let’s talk about auto release Pole now as we create objects memory is going to be set aside for our application as well as our objects and whenever those objects are no longer going to be needed there is going to be memory that is going to be D allocated so that that memory will be released for other parts of our application an auto release pole is going to do that for us you also will often hear about a RC or automatic reference counting and basically what that does is it just automatically for us signals for the destruction of objects when they’re no longer needed so that is why we’re putting all that stuff inside of Auto release pull with our little curly brackets now NSLog is going to work exactly like printout for very similar anyway you can see right here it opened up and it printed out hello world the only difference is it’s also going to put out like a timestamp there we’re going to be creating a lot of objects one of them is going to be an NS string and this is a string and it is going to more specifically it’s going to be a string pointer and very often whenever you are creating an object and you want to define it but not give it any real specific information you’re going to assign it the value of nil which means that it is a non-existent object inside of memory and all of these non existence objects inside of memory are actually going to point to the same place because this is a pointer right here once again in NS log you know start off with the @ sign and I could say something like location of nil these are always going to be the same and it’s a pointer of course and we could say something let me just point it nothing like that and you’re going to see the location in memory for nil and it is always going to be the same 0 X 0 let’s now come in here and actually create a real NS string and it’s just a string that’s all it is so we’ll just go in a string or a pointer to the string in memory I guess is what I should say and we can come in and we go at and then we could say something like there we go and because NS string is actually an object it’s going to have a bunch of functions or methods F say or refer to and now I’ll show you how to deal with them first what I’m going to do is I’m going to use the NS string objects and show you how to interact with objects that way and then I’m going to show you how to make custom objects so size of string there’s actually a method inside of the inner string object that is going to give us the length of the string make sure you put that column inside of there and I want to cast this to an integer and how you would call the quote objects length method or function is write like that put it inside of brackets put the name and then put whatever the method is you want to call and if you do so you’re going to say size of string is 40 that means it has 40 characters and if you count all that up you’ll find now that that is true so that is sort of the weird objective-c way of calling methods but you can see how that’s done now to do something a little bit more specific to NS strings let’s say that we wanted to come in here and get a specific character let’s say we want character in the index of five here we’ll actually get the character there is another method character at index five and that’s how you pass in an attribute to a function or method inside of objective-c colon and then whatever you want to pass inside of it also a little bit different from most programming languages and you can see a character at the index of five is H and if you count it you’re going to see that that is indeed true you also will be able to come in here and create a dynamic type of string so you could say my name is equal to and by dam dynamic I mean that right here this is a non dynamic it’s given a value and it’s assigned here we could put in a variable and you know dynamically generate it however if you wanted to do that what we’d have to do well first off let’s come in here and we’ll say let’s create a string name is equal to Derrick like that and then inside of here to create a dynamic string we go string with format exactly like you have right there then after this we put at and then we put something like – and there’s going to be the new string that we’re going to be adding inside of there and then name right like that and that is how you would create a dynamic string you could test if two strings are equal you’re going to be using boolean different type of boolean inside of here

versus what we had previously with our C part we call this is string equal and how we could compare whether they are equal is is equal to string is the name of it then you’re going to put in my name like that whatever string you want to compare it to and here we’re saying is the quote string equal to the my name string well of course that’s going to come back false and just to prove that you can still use printf see there’s printf even though we’re inside of an objective-c program or application so we can say are strings equal and then we get our answer right here is string equal if we run that you’re going to say that the answer are strings equal comes back at zero or false if you wanted to convert an NS string into a regular old string you could of course do that as well it’s a little bit weird because we’re going to have to use what are called nested messages this is known as a message right here whenever we are calling a function or method inside of the object that’s a method we actually put that messages inside of messages here I’ll just show you what that looks like can also create constants with Co NS T and in this situation you’re going to need to do that so see a string is equal to and we can say my name could also change it to uppercase string if you’d like to just throw that in there just for the heck of it and if you wanted to convert this into a regular string string you would follow this with utf-8 string like that you don’t need the uppercase string part here I just put that in there just to do it this is the part you need to do if you want to convert from an NS string over into a regular old string like we have right here and we close that off so what this is going to do is it’s going to create an uppercase version of this guy right here my name and let’s use printf again and to get it will go you see a string like that and execute it and there you can say it made the name uppercase and it converted in and regular string and printed it out because that’s what we have right there you could also come in and combine strings and we’ll just go in a string say something like hole quote and to do that and this is what I mean by nesting or inner messages right like this say there’s one of them and then there’s one there so we’re basically making it uppercase and then we’re converting it into a string so then make sure you caught that so if we want to combine strings we go string by appending string right like this and we could say my name so we’re going to tack my name on the end of the quote string we could then come in and search for strings how we do that is we define NS range like this and we could call this search result is equal to and we could say whole quote and then we have to define range of string and then an axon and whatever string we specifically are looking for I’ll just put my name inside of there and this doesn’t have anything to do with whether it’s uppercase or lowercase it will find it either way then what we could do is we could say if search result dot location is equal to NS not found and we could print on its log inside of here say something like string not found else in that situation that means it was found and we could say something like print up Derek is at index Lu and is Lu long it’s going to tell me the index it’s at and how much space it’s going to take up and to get that information we go search result and location there you can refer to attributes or properties or variables of the objects by using just a regular old dot operator and then search result again and then if you wanted to get the length for it that’s how you do that I’m going to show you a whole bunch of these guys like I show you every one of them but you can see index 42 and it’s five long and there’s five characters so you can see that’s true we could also come in and replace a substring by defining at what index to start replacing and then how many letters to replace how we’re going to do that is within its range again and let’s just call this range is equal to where you go NS make range like this and we’re going to start at the 42nd character because that’s where we said it was and then we’re going to say five characters is how many way we’re on we want to replace and then we can go constant character and let’s say we want to call this new quote is equal to and we could go whole quote followed by and then string by replacing characters in range after you do this enough you’ll eventually get used to using it there it is string by replacing characters in range Objective C is a little bit weird there’s some strange sort of things that wants you to do here but either way then you type in your range with straw it automatically knows what you want to put inside of there and let’s just say that I want to come forth and say I did not create that quote but it was an anonymous quote so we’ll just put anything on inside of there get rid of all this stuff and then let’s also convert this into a regular strain utf-8 string like that and like that and then we could print that out so I’m just print four enough and new quote and

there you can say dogs have masters while cats have staff and you can see that it replaced my name with a non or anonymous now one thing it is you should know about using NS string is this is what is called an immutable object sounds like a big word it just basically means that once you assign a value to it that value can not be changed we’re going to be creating new arrays every single time we make any type of changes if however you wanted to have strings that could change you’re going to instead use NS mutable strings so let’s say we wanted to create a grocery list for example we could do so and this is going to be an S mutable string like this if we wanted to define the initial capacity but knowing that it could definitely change we’re going to say string with capacity and then give it a value of 50 we could then append a value to this string by just going grocery list and append format and then put in all the different things that we would like to add to it we can go string like this and then we could say something like potato banana and pasta and that’s how we could append to our mutable string first your list if we want to put these values inside of here we’re going to put % and ampersand and then just grocery lists like that make sure you come in here and put an @ sign in there did it data and there you can see it printed out all of our grocery list items we come in and delete characters in a range also with the mutable string we’re just going to say grocery list again and then we’ll define the start and the end so to do that delete characters in range like this and then this is going to be NS make range like that and then we’re going to say start at the first and then go to 8th out and delete all those characters we can see here exactly how these would be changing there you can see potato banana pasta here we deleted the potato part off of there could also come in and insert a string at index grocery list again and then we could just go insert string that’s on and we could say Apple close that off at index and then change that to 13 renowned our grocery list again there you can see apples on there now we could then also come in and replace characters in a range we’re going to say grocery list again replace characters in range exactly like that we’re going to say NS make and we’ll say we start at the 15th and 5 characters long and then with string we’re going to change that to orange and then we could print out our grocery list again and there you can see apples been replaced with orange and now we’re going to take a look at how arrays work inside of objective-c so NS array is the name for an array inside of objective-c and let’s say we have something like office supplies we could then define them by putting the @ symbol like this followed by all of the different things you want inside of here so we’ll say pencils and arrays are just like boxes inside of boxes that all have indexes or labels or whatever you want to refer to the mast and we’ll go paper would then be able to access the different values inside of these guys by going NS log at and let’s say we want the first item inside of here we get that first item by % + @ symbol and then remember the first item inside of an array is in index 0 start off by counting to 0 and then we can come in here and print all of them out if we’d want again we’re going to do the same sort of similar thing that’s on and off supplies and we put the odd symbol in error again and this time we’ll just type in office supplies no specific anything and run that and you can see that the first thing in our array is pencils and you can see right here office supplies and it’s going to print all of those out all at one time you can of course search for items inside of here again we’ll just create a boolean value and we’ll check to say or check to see if it contains an item to do so office supplies of course is an object and one of the methods inside of it is contains object that guy right there we’ll just put inside there exactly what we’re looking for which is pencils and then we can come in and check and souls need pencils whatever you want to put and D execute and you can see right here need pencils comes back true that means true that the pencils are inside of the array could also get the number of items inside of our array quite easily at symbol and let’s say we want to say total and let’s convert this into an integer have to do that cast and then we’ll just call office supplies again and the specific method we want is count again comes back is two and we know that that’s true now that we know that the pencils item is inside there might be useful to be able to jump inside of there and get the index of it so NS log at index of pencils is at and then here we’re going to put Lu and this is going

to be an unsigned long that’s how we do a cast for that and then to actually get the index we go office supplies again followed by the method called index of object there it is and then we just tell it specifically what we’re looking for and in this situation that is pencils semicolon and index of pencils is at index zero now again NS array by default is going to be immutable which once again that just means that it is not going to allow us to change it it is going to have to create a new array each time if you want to create a mutable array that you can add objects to you go announce mutable array and let’s say that we want to create one called heroes this is NS mutable array of course and we can define a capacity to start off with but like I said we can add to it ray with capacity and let’s just start this off at five we can then easily add heroes by just going euros add object and then we can put in Batman or whatever you want to put in here and we’ll throw a whole bunch of these in here we could then easily also come in just by calling the heroes method and insert an object inside of here let’s say hey we forgot Superman so let’s throw him inside of there and we can say where we want to put them at index and let’s throw them in the second index and so automatically going to make room for them and let’s show exactly what we have here and there you can see it printed out all the heroes Batman Superman Wonder Woman Kid Flash all of them all in one place now if we can add items of course we’re going to also want to be able to remove items we can go heroes remove object and let’s say that we want to remove flash we can do that we could also remove an object at a specific index so heroes remove object at index like this and let’s say we want to remove whatever is an index zero there we go just did that we could also come in and remove objects by name so heroes remove objects identical to and let’s say we want to remove Superman we could then go in range and define a range for this NS make range and change this from zero and then change this guy to one and then finally we could actually iterate through our array and to do that just go for start at zero that’s the first one while I is less than if we want to get the number of heroes that we have heroes count and then go and a slog and print all of those out on the screen and of course we can refer to them all by whatever their indexes and there you can see it printed out Wonder Woman and Kid Flash which were the only heroes left after all the other changes we made and now it’s time for us to create our own custom objects and to do so we’re going to come over here to our project right there we’re going to go object right there and then file new we’re going to select Coco class and click on next we’re going to call this guy animal and subclass of nsobject which is the number one object that is used for everything and click on next and then we’ll click on create and here you’re going to see it actually created a header file and this is where we’re going to be declaring our instance variables or properties or attributes or whatever you want to call them as well as the methods and then in the EM file that is where we’re going to be implementing or writing the code for our methods so we’re going to start off in our header file and you can see right here the object that it is going to is the superclass for our animal object it’s going to inherit everything that is in the nsobject and in the header part dot h this guy right here that’s what we’re in right now we’re going to define our attributes for our objects and these attributes are not going to be directly accessible however getter and setter methods are going to be automatically generated as long as you want them to be and how we’re going to create those well first off let’s say we want to create an attribute that is not or a variable or an instance variable where we want to call it that is not going to be set of all what we would do is go at property and read only this is not going to have a setter method generated for it automatically and let’s just say that it’s an n/a string and it is called name so that is how we would create something that could not be set from directly for our object however instead we’re not going to do that for now instead we’re going to allow this value to be changed now let’s think about our animal and all the other different attributes that should have it should also have a favorite food probably let’s make that an NS string create another one property and a string and maybe it’ll have a custom sound that it uses let’s also create a primitive inside of here property float weight and just remember if it’s a primitive it’s not an object that means it doesn’t need the little star inside of there which is our pointer and then we need to define different methods that we want to use inside of here well every time you create an object it is going to call an initialization for object which is going

to set certain attributes that we might want to set so those are automatically generated by default for us but let’s say that we want to come in here and define a custom way for us to initialize our files now again remember we’re in the header section here so what we’re going to do is define what will be returned so an instance type which is going to be specifically an animal instance and then we could say something like init with name and let’s say that whenever this is created it’s automatically going to be passed a string have to put the star there and let’s say that it’s going to be possible to create an animal object and pass in a default value let’s go and create a couple more methods let’s say we have another method there are objects going to have that is not going to return anything and it’s going to be void and the negative for it whenever we put that there that means that this is an instance method which means it’s a method that’s specific to objects that we create of type animal if we put a plus sign in there however that means is a class method and a class method will not be accessible whenever we create an animal object we’ll get more into that here as we go on so let’s say this one is just get info it also is not passed any attributes while this doesn’t really have much to do with an animal I’m just trying to think of something let’s say that we want to return a float which is going to be weight in kilograms let’s say we have a really smart animal that can do conversions if you wanted to create a method here that is going to receive a float that’s how you would define that and you could say weight in pounds is the attribute that’s going to be passed to this method so this is going to be the method name or the function name it is going to return a float right here is going to receive a float right here and the float that it receives is going to get the name weight in pounds we could also set this up so that we will be able to return a string and in this situation go to put to the store inside of there and let’s call this one talk to me and it is going to receive and then a string sent to it and that NS string is going to be whatever the person’s name is and it’s going to pop out a little bit of information directed it whatever the person’s name was let’s say that you also want to receive multiple different parameters well this guy is going to return an integer and we’re going to call the method here get some and it’s going to receive an integer let’s call that number one and then we can go to the next line here and say next number and this is going to be an integer and number two in this next number right here this can have any name you or what it is what’s important here is get sums the name in the method it’s going to receive two attributes one being number one and in the other one being number two both of which being integers it’s going to sum them and return those as an integer well now what we’re going to be able to do is jump into the animal dot M file this guy right here and implement all of those methods that we just created now you can see it has a reference to the animal dot H file which is where we defined what we want to create and here let’s say we want to throw in the initialization file where the constructor is it’s very often called let’s do something a little bit interesting here let’s come over and open this guy up and then let’s specifically come on down here to where this guy is right here click on that then down inside of here we’re going to click and we’re going to go in it see right here Objective C and NIT method that’s going to allow us to drag and drop this over here it’s automatically going to put in all the code that we are going to need for initialization method that we want to create this is the default it’s called a net remember over here we defined we also wanted to have another init with name so one is going to set the name if it’s available and the other one is not because it’s not available and this allows us to think about a couple other different things whenever we have self inside of here self refers to the instance being initialized because we have no idea what the animal objects name is outside of here so anytime this is like this and many other programming languages so anytime we want to refer to an instance by itself then we would just use self inside of here this is a call to the superclass and it’s going to perform any initializations that are needed there and the superclass is going to be nsobject this guy right here and then down inside of here what we could do is we could say self for the object being created we could change the name or create a default name of no name whenever the object is generated and then we’ll know that our animal hasn’t been assigned a name yet now what we can do is we can create our customized and knit and how we’re going to do that is this again is going to reserve an instance type and that just means this animal instance type it’s just a generic way to refer to initializations and in this situation we have and it with name and default name you can see all those things automatically popped inside of there as we define them here see default name all this stuff automatically jumps right in there makes it very easy to create these methods and here what we’re basically going to do is

the same thing we have here except we’re going to actually define the name that we want to use which in this situation is going to be the default name that was passed inside so default name right like that now we need to define all the other different methods that are going to be needed that we defined in our header section so let’s come in and define get info first off let’s just make this really generic let’s go and it’s log and for now we’re just going to have this just be random info like that we could then go and get our float method we’re going to create we could then go and define our weight in kilograms method that we went and created and automatically generate that for us and we’re just going to take weight in pounds I’ll apply that times 0.45 3 5 we had another one this one is going to return an integer and this is get some say it automatically generated all that for us here we can just go return and then this would be number 1 plus number 2 it comes down to one of our last methods we defined which is talk to me again and a string like this make sure you put the star inside of there and then let’s define talk to me and in this situation we’re going to define ans string which is going to be let’s put a response inside of here it’s equal to in a string string with format and here we can say hello at symbol and then my name so whatever name they pass inside it’s automatically going to respond as if it knows who that person hits and we could say return response okay so now that we have those objects defined we can go back into main dot m and start playing around with them so if we want to create a new animal object we just say animal and let’s say this first animal is dog pointer to the dog object and we’re just going to come in here and go animal which is defining the object type allocate some memory for me and then we’ll call an it which is going to initialize everything for us that’s how we create in dog objectory in wall object we could then call for a method to execute dog let’s try get info and that’s how we would call that just like we saw previously we’re going to want to come up here though and import our animal dot H file sure you do that otherwise you won’t be able to call all these if we wanted to get a value that is stored inside of an instance just use an S log something like the dog’s name is and then to get the dog name will just say dog name like that automatically that’s called a getter and they’re automatically generated that’s a way to get the name for our dog we could then also come in and set the value set name that’s how it’s done and let’s say we want to call our dog’s spot no it’s going to be called spot now and run it just to show that everything’s working here say random info printed out that’s what that method did dog’s name starts off as no name and then it gets changed to spot so just to show you that the objects are working here and we’ll create an animal objects we could also call the custom in it that we generated let’s have cat is equal to to call the custom Annette we’re going to go animal allocate memory just like we did before except in this situation where you go and knit with name remember we provided that and in this situation we’ll say whiskers is the custom name and if you don’t remember that’s from over here da-da-da-da-dah c init with name so we’re calling that instead of calling this initialize file now you don’t always need to access variables using dog name like this we’re also going to be able to come in and get those using a dot operator and let’s just do that with cat here the cat’s name is so in sign at and we can just say cat dot name and then let’s just call all of the other different functions we created here just to show that they work let’s say we go 180 pounds is equal to and let’s get this converted into kilograms F kg and once again to call for that method to execute we just go whatever the methods name is weight in kilograms and then we pass in 180 there’s the attribute and there that is again we can just to come in here and pass in multiple attributes just to show you how that’s done so three plus five is equal to and that’s going to return an integer and passing multiple integers or multiple attributes we’re going to go get some call the method that we want to pass in there and we want to pass in a three and then the next number we’re going to pass in is a five we want to pass in a string inside of here % @ symbol and here we’ll get a dog talk to me and then we’ll pass in my name and there you can see I executed all those and how they all work ok so there’s multiple different ways to deal with multiple different types of methods with different types of attributes and different types of return values all on custom animal objects the other thing is neat is we’re going to be able to create let’s say another animal type let’s say a koala bear that inherits all the attributes or variables from the animal class as well as all of the methods automatically and we just come in here

and right click on this and say new file this opens up and we’re going to say source class and we’re going to say next and we’ll call this koala and subclass of this is going to be of animal and objective-c of course nothing else is going to change there and then just click on create and now we have a subclass named koala that’s going to inherit everything from our animal class and how we know it inherited everything from the animal class is there it is right there that is how we know that it’s inheriting all that stuff now in the header file for koala we can come in here and override methods for example so let’s keep this nice and short and a string and let’s say that I want to overwrite the talk to me I could overwrite everything if I want keep everything the same here in our header file then jump into this koala port right here again and a string and the method I want to override jump into here and just get this just to save some time talk to me paste that in there and we’ll say hello bah dah dah dah dah says and then we’ll get the koalas name to show up inside of there and how we can do that again is self dot name that’s how we refer to that so we went and right at that guy we could then create custom methods that are only available inside of koala jump over into our header section and let’s say void form trick let’s call it that and it’s not going to receive any attributes and then we’ll create another one void and we’ll call this one make sound just to show that we can create them all of these guys save that jump over into koala and then what’s define all those so – void form trick there that is I’m going to find what it’s going to do slog and we’ll say that we want to put the name of qual inside of here whatever that’s going to be forms a handstand self name there it is and then we’ll define also other guy and that’s make sound and a slog they’ll just say he owns self name now we jump back over into main and make our quality ice stuff so it’s an object it’s koala object and it is a reference it’s an object let’s call it herbie is equal to and it’s going to be koala object going to allocate it some memory say we want to initialize it by name but make sure we come up here and actually reference the koala header file there it is and then pass inside of here it’s calling kirby so now our koala has a name and then we can demonstrate our overridden method that we created here and we can call our herbie method talk to me and then pass inside of it my name see how that changes and actually i think i’m going to take those other methods i created in a koala and demonstrate something else so and if we run up unexpected da-da-da-dah up make sure we put an app symbol right there whoops make sure we take that out of there and execute it there you can see hello Derek and hello Derek sorcerer B so that’s how we overrode those and how they work now categories are going to allow us to split our class into many different files and at the same time keep our file size is manageable and how we’re going to create a category is once again come up here right click on this file new and then we’re going to click on Objective C file not Co class Objective C file click on next then down here click on category and I’m going to call this exam and the class specific to it is going to be animal and click on next and then click on create it’s going to create animal plus exam dot H now in our header file that we have here for animal exam at run time we’re going to be able to add methods as part of the animal class and what this one’s going to do let’s create something that’s a boolean and call it checked by that and create another one say it returns nothing and get shots then we’ll be able to save that jump over into the implementation file here dot m and implement these guys so let’s go and create a boolean check by that and what it’s going to do just keep it simple we’ll do return 1 for true save by default it is checked by the vet and we’ll go and find the other guy get shots and s log and we’ll say whenever this calls it’s automatically going to say that whatever the name of the object is got it shots there you go real simple now well we’ll be able to do jump back over into main I like this and let’s continue working with her B we could then go and it’s log at did since I’m at check if her we got it shots of course we could have that set to a variable and turn it on turn it off and get her B’s name followed by her be checked by that and then also her be get shots and call that method and then get that to work all we’re going to need to do is import that category and that’s just animal exam automatically is going to place that inside of there and all that’s going to work and there you can say did herby receive shots yes her we got it shots other thing we can do is allow files to

import a category but at the same time block access unless the class is a subclass so we’re not going to be able to work with anything unless it is a subclass of this class that we’re working with so we’re going to come over here right click on this file new file again source this is going to be an objective-c file click on next and I’m going to call this protected this is going to be a category as well actually it’s called this vet category type animal click Next great or that is jump over here to the header file and then instead of that this is going to be called protected let’s define our method we want to create here void and then let’s call it get exam results something would be maybe private I’m able to jump down here and implement that get exam results and it’s log and we’ll just put something exam is fine doesn’t matter no what we can do is jump back over into animal implementation area right here and then let’s say something like in the get info area if we wanted to specifically call that we could just very easily come in here and go self get exam results of course we have to come in here and import this there’s that animal that and then get exam results close that off and that’s always it was to add that protected method that of course we’re going to call that we could just come in here and get a dog and get info of course and that would automatically call that as you can see exam is fine print it out there on the screen now just to say I’ve covered pretty much everything I’m also going to cover protocols and I started doing that a little bit with Herbie the Koala and we’re just going to come in here again right click on this and say new file accept and Objective C file is fine and we click on next and this is going to be a protocol right here and I’m going to call this beauty contest and a protocol is just going to be a bunch of properties and methods that any class is going to be able to implement and you can see it doesn’t have any animal class or any other reference to a class click on create and here is beauty contest which is going to have just the header file part of it and here we’re just going to define the methods and then stick them in any place that we feel like putting them and I like I said I already started doing this with the koala forum trick there it is so generated that jump over into the koala and you can see I didn’t need to define it right here I just need to come in and define that I want it right here beauty contest there it is and now I can jump directly down into the implementation and define perform trick and look cute or whatever I wanted to put inside of that so let’s come in here and go look cute where’s Boyd cute and we’ll say Herbie acts super cute or at least that’s the way it works because its name is Herbie so and name and that’s in the Koala implementation file and if we jump back into main we can see that we can just go like this Herbie look cute that’s going to call that and then Herbie form trick and then to implement that you’re just going to have to go over into your header section right here and add that in as well so beauty contests like this close that off if I’ll save that jump over into main execute it and there he is Herbie act super cute Herbie performs a handstand really easy to slide those methods in right there now to make sure I cover just about everything I’m going to go over a block around an anonymous function in objective-c how you would create one of those is you would define whatever your types going to be we’re going to say at say I want to create an anonymous function called get area then we’re going to define exactly what is passed into it so the height as well as the width are going to be passed inside of it you’re then going to assign the block to get area how you do that there’s that carrot symbol float then we’re going to say float with float height to find exactly what it is going to do it’s going to return the width times the height to get our area and then make sure you put a semicolon at the end of that then you’re going to be able to come in here and just use it so we say something like at area of 3 wit and 50 poit and that’s going to be a float and then we’ll just be able to go get area just like any other thing by passing in 3 and 50 and you can see there it worked so that’s how we create blocks enums are going to be used whenever you want to define a custom variable with a set of constants and how you do that is just go enum let’s say we want to do like we ratings or something like that could come in here and go poor is equal to one okay is equal to two I don’t know great is equal to five so forth and so on and then if you wanted to assign those values you go enum ratings which is the name of it and matrix rating or for them movie The Matrix and you could just define great inside of there and you just go matrix since on you matrix writing like that up make sure you put a semicolon right there and there you can see matrix 5 shows up automatically then the final thing I’m going to talk about is dynamic binding and this is basically going to allow us to create objects subclasses that all have a superclass

type that they would share ok and to demonstrate this what I’m going to do is I’m going to go into my animal header file this guy right here and I’m going to initialize a new method and this is going to be void and it’s going to be called make sound save that then jump over here into my implementation file and fun it right like this this is very similar to what we call polymorphism just allows us to refer to a group using the superclass and let’s say that it just goes ger the default animal sound is go let’s go then and create another object so file file new and let’s call this this is going to be a coca class next let’s call this dog again some class of animal objective-c click on next yes create it and then inside of the dog file well I want to jump over into the header section first inside of this we’re going to well actually I don’t have to do anything it’s automatically is going to get the make sound method of course however I’m going to override it and I’m going to say Boyd make sound this is in the implementation file of course and it’s logged and here I’m going to say something different so we’ll just say blank says wolf and then refer to the dog’s name over in the koala did it tada what yes I automatically I went and put make sound inside here so the koala and the dog are both going to totally different sounds that they make and that’s going to allow me to come in here and demonstrate dynamic binding so I’m going to do is I’m going to create a dog let’s call him Grover equal to dog allocate some memory let’s initialize him with name also let’s come in here and import dog H there’s lies with name and his name is going to be Grover now what I can do is create an array and refer to everything as animals and SRA allocate some memory and then I’m going to knit with objects in this situation and the objects I’m going to put inside of it is going to be Herbie and Grover that last part being nil now I can create some generic IDs which are just pointers to any type of object type they’re as generic as anything could ever be I’ll just refer to them as object 1 and we’ll say that these animals just what I’m referring and I’ll say object at indexes and I’m just going to put 0 you can see I’m working with the most generic type of object possible and I’m throwing those into this array and we call this object to animals object there is the second object in that tier and now I can just come in and go object 1 make sound and object to make sound and it’s automatically going to call the correct one well change this to index and when you execute it you can see automatically Herbie says yawn and Grover says wolf so there you go guys I’m going to also include a couple other different things on my website that I didn’t cover here but I covered so many different things just when to cover as much as humanly possible please leave your questions and comments below otherwise till next time