Posts

Showing posts with the label Coding

Treehouse Intermediate Course - Part 12 (Closures 3)

Image
OK, so a change of plans of where I was yesterday. No matter - an entry before bed instead! Just enough to keep things ticking over. I'm then in Liverpool from Wednesday until Friday. Depending on my use of wifi/hotspot on the journey, I may be able to add in something during the journey there and/or back. Right, enough prelude and let's get going. A quick session! Start Time - 21:33 Map Standard Library Functions - certain aspects on Swift are already built in. So without the use of a closure - how to transform an array of ints so that they are doubled: let values = [ 1 , 2 , 3 , 4 , 5 ] var newArray = Array < Int >() for number in values {     newArray . append (number * 2 ) } This is the alternative.  let doubledArray = values . map { $0 * 2 }  So interesting tech speak here. The first is the imperative approach - showing line by line instruction. The declarative - the closure one - shows the end result wi...

Stephen DeStefano Swift 5 Course - Part 3 (Lectures 8 to 11)

Image
Well it's been a good few days but I'm back! No need for more of a preamble than that - straight into functions! Start Time - 14:06 Functions These are SELF-CONTAINED. It is best to name what the function actually does. Syntax - the name, parameters, return bit etc. Nothing else new here. Bit about the return value and print statement used. Underscore - placeholder for a constant/var without an actual name. 9 out of 10! Only one that was wrong was a bit of a trick question. OK next! Returning Multiple Values So this of course means returning a tuple All very technical - again, Stephen combines lots of elements - for loops, if statements, optionals...all hard to keep on top off! Names of return types - optional. Used to improve readability of code. Argument Labels and Parameter Names Argument label - used when calling the functions. Better for readability. Swift used the parameter name as the default. Labels are used on the outside - on the left of th...

*Consolidation Entry* Closures Part 2

Image
Here we go - back to two entries in a row! As I mentioned, Ramadan is about to begin, which means I'm around a calendar year from on where the 'relaunch' of my coding journey began. In fact, let's just take a little trip back to this time last year.... In fact that was 4th June! At that point, I went back to basics and started again using Treehouse to go through all of the content. Before that, towards the end of December in 2017, I made a go at a relaunch there, but it was pointless, as were the several entries in between then and June. So really, it's been 11 months. In that time, I really have achieved a lot but should NOT be too hard on myself with what I CAN'T do. Let's just focus on what I am able to do! Not going to do a break down now - will save that for a month when it is a full year! So for now, I just want to cap off closures... Start Time - 20:37 Just to go over the very last bit from before - This was the creation of a closure. So spe...

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)

Image
No time to waste! Only got a short amount of time now so going to get a few minutes or so in! Start Time - 20:14 Conditionals If statement for 'love calculator' example. So a simple example for this. The idea will be that conditionals are used to show that the print statement will do it differently for whatever the number is. With updated Swift, I would use the Int.random(0...100). Easy fix that would be. Also no UIInt32 needed but just an Int. So with the if statements, it would be a STRING being returned.   Linked to the whole choose your own adventure - if/else for each choice. BMI Challenge No need to do this - easy enough to be honest. Just skimming through. BODMAS principles... So something I picked up on before is not needing the greater than AND less than value for the middle line (for the else if bmi > 18.5) A better solution, which Angela is already explaining before I could say it is returning a string instead of a Double. So the...

Angela Yu Xcode 12 Course - Part 6 (lectures 55 to 73)

Image
Here we are! Last time was such a short entry and this one will be fairly brief too! So I've got a bit of time now and most likely no more until tomorrow. Am enjoying Angela's course immensely - so may bits seem fresh and new, so well worth the £10. Every time she brings out a new Swift course I have to get it! Anyway, diving in... Start Time - 12:32 Magic 8 Ball Project Right, making Magic 8 Ball App. Even though I made this once around 6 months ago, am going to try it without any tips! Let's go! Right app icons...yes it worked! Had to check the Dicee way from a few lessons ago. Basically, I need to empty that folder including the JSON file. Then replace it with the whole folder of new app icons. Cool! Right so the IMAGE files need to be actually clicked and dragged into the image folder ON XCODE!! Cool, using Ray's tip, I'm going to do my to-do list rather than follow Angela's steps - much more of a challenge. This is what I'm trying to creat...

Angela Yu Xcode 12 Course - Part 5 (lectures 51 to 54)

Image
After a couple of days where I literally had no time to code, I am back! Cracking on with Angela's course. As before, for these projects I am just skimming through and working out any answers to her questions as I go. Right let's start! Start Time - 20:41 Arrays in Swift Image View - think of these as a picture frame. Something will go inside. So that is the code for changing the image view - using the property of image then the UIImage class. So that will make the left die show 'dice 2'. Of course the best way to do this would be to create a dice array. E.g. var diceArray = ["dice1", "dice2"...] Then have the random integer in the [] shown each time. Arrays - no need to go over this. I know they're the same type, start from index 0 etc. So instead of 1 in the square brackets, use the randomDiceIndex1 value. That will mean a random one each time. Same for both dice. Easy! DRY Principle Don't Repeat Yourself! OK th...

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...