Posts

Showing posts with the label arguments

Sandra L Course Part 3 (lectures 16 to 22)

Image
Well it's been a good few days! After so much success with my first proper app, it's been a shame not to capitalise on that. Having said that, I do feel recharged and ready to learn some more! My plan with Sandra's course is to keep with it for all of the recap. When it starts getting trickier, I'm going to work on an Xcode project for another app idea - got a few possibilities! So, let's continue with Sandra's course! Start Time - 13:29 Parameter Labels func add(number1: Int , number2: Int ) -> Int {          return number1 + number2 } add (number1: 4 , number2: 6 ) Again, easy stuff. The next step here is to use _ to have empty parameter labels.  OK - one useful distinction here between parameters and arguments. The argument is the external name - the one used outside of the code block. The argument label should read as a sentence e.g. using 'to' instead of 'name' in a sayHello function.  So "say hel...

Object-Oriented Swift - Complex Data Structures

I am now onto the next course! This is the last full course I need to recap/redo before continuing with the one I got to before. All of the skills I have built up over the past week or so have really made me feel positive about Swift. The next lot of videos are about 'structures' - bundling together a number of variables and values. It is going to be a step up.... Introduction to Structs The first example Pasan gives is vaguely familiar - it's about using coordinates for shooting towers for a game. The number of values needed means that we would need to create a struct. Creating a separate value for each of the x and y axes are useless. Creating a tuple would be better as the x and y values are linked together.  let coordinate1: (x: Int , y: Int ) = ( 0 , 0 ) This is fine but is going to be quite limited. Instead we are going to create a custom struct. As struct can define variables or constants, which are called stored properties. No value needs to be ass...

Functions (part 1)

So I am now on to the next course! This one is all to do with functions. These I remember fairly well from before but, as I've found, it's not so much the concept but the application of it that I find trickier. We'll see how it goes! What is a Function? Pasan explains this through the example of making coffee - a series of steps for a very specific task. When needing coffee, the sae series of steps are carried out! DRY - Don't Repeat Yourself! So, rather than going through the steps of something e.g. making coffee every time, we can just call up the function of making coffee. A coffee maker carries out all of these steps so you don't actually have to do each one. It is a 'self contained block of code that carries out a specific task'. Functions in Code let length = 12 let width = 10 let area = length * width I think the point that Pasan is going to make here is that it is cumbersome to keep changing values or doing this each t...

Creating Objects from Classes

Well, it's been a little while! The last time I blogged about using Swift, I was on my Christmas Break from work. Predictably, the first few weeks of term have been busy so there has been little to no time to open up my mac and do anything coding related. So today is the first time for over a month. Too long! I remember this feeling when trying to write regularly into a diary or journal years ago. There would always be the associated guilt of not updating it often enough. It would've been tempting today to have abandoned the idea of doing anything Swift based and go for the cliched 'I'll do it another time'. But as I've mentioned in previous blogs, I'm determined not to undo and unlearn all the knowledge that I had steadily built up in my sojourn from work recently.  Anyway, onwards and upwards. The next chapter I'm tackling is all about 'Creating Objects from Classes' (Chapter 6 - pages 83 to 94) . As before, I'll do a 'live' blo...

Calling Methods

So, starting from my previous post on 'Optionals',  I'm focusing on one area/challenge of Swift at a time, with my immediate reactions and reflections on them written in this blog. As I've mentioned before, the purpose of this is to help me make sense of what I am learning, not revel in my lack of knowledge! Also, as before, the source material I am using to learn about Swift is from the same Ebook as before: 'Learn Code in Swift 4' by Kevin McNeish. This time I will also supplement with this from other courses I have used in the past, e.g. Treehouse to help me understand the information in context. Calling Methods So the purpose of this chapter in the Ebook is to do with appending. So, first of all, what is a method? A  method groups together one or two more lines of code that are then executed as a unit. I've always thought of these as a function put into context. E.g. 'print' is a method, or is it a function? As with any element of Swift, ther...