Posts

Showing posts with the label functions

Ray Wenderlich Functions and Types Course - Part 2

Image
Back on it! Two entries is the plan today - half an hour now and then again later - so as one blog. Let's go! Start Time - 13:01 Advanced Parameters Variadic parameters - So this can be an unspecified number of parameters. E.g. in the print function - could be one or more things to print! Here is an example - func getBestGrade (for grades: Int ...) -> Int {     grades. max () ?? 0      } getBestGrade (for: 4 , 7 , 1 , 8 , 19 , 3 ) This is different to what I assumed. I thought it would be an array.  Inout parameters func incrementAndPrint (value: Int ) {     value += 1     print (value) } Now the issue here is that the value parameter is a CONSTANT by default. It is immutable! So to fix that we need the inout keyword... func incrementAndPrint (_ value: inout Int ) {     value += 1     print (value) } OK a couple of things here. It only w...

Ray Wenderlich Functions and Types Course - Part 1

Image
No need to go into the obvious lament of how long it has been! Let's just say that it's a fresh new year and new start for 2020! The mini project was great - learned a lot of skills in practice. Now it's time to look at rw.com and decide what to focus on next.... Start Time - 20:34 Right here we go functions and types! It is recommended for what to do next (other than the awful to do list project, which I abandoned). Just approx 30 minutes today. Introduction We will start with what we already know about functions, then go on to more complex use of them. Then onto closures - yes! I need that badly! I really want to use the closure features a lot, lot more. Then enumeration - cool. Next onto properties and methods. Finally, classes and protocols. All on Xcode playgrounds. Get the beginner playground and work alongside Catie. Challenges along the way, cool. This is cool - I feel like I need to get back into the technical stuff rather than ploughing on with proj...

Ray Wenderlich Fundamentals Course - Part 4

Here we go! Last chapter of the course for fundamentals. This one is a bit longer so may need two entries. Let's go! Start Time - 17:39 Compound types - e.g. for tuples. This is about information being bundled together. Value and reference types - we'll be coming to that! Functions func printPass (grade: Int , pass: Int ) {     if grade >= pass {         print ( "Your grade score of \(grade) has passed! You passed by \(grade - pass) ." )     } else {         print ( "Your grade score of \(grade) did not pass!" )     } } printPass (grade: 72 , pass: 50 ) I've elaborated on this a bit.  OK, difference between parameter and argument. It's called parameter when declared. When called, and providing values, it is an argument! Cool, that does clarify.  func printHighestGrade ( _ grade1: Int , _ grade2: Int ) {          print (grade1 ...

Lynda Course - Swift 5 Essential Thinking (Part 4)

Image
Am smashing through this course and enjoying it! Probably because it's mostly recap and consolidation. Anyway, got a bit of time before a brunch today so no time to waste! Start Time - 11:26 5. The Wide World Of Functions So a point here is that a lot of these are already built into Swift. But we can create our own of course! Basic functions All good recap here. Overloading functions Heard of these once before in Pasan's story course. So this is using the same name for multiple functions, as long as their signatures are unique. // Base function func attackEnemy() {     print ( "Attacking enemy..." ) } // Overloaded functions func attackEnemy(damage: Int ) {     print ( "Attacking enemy; \ ( damage ) caused" ) } func attackEnemy(damage: Double , weapon: String ) -> Bool {     if damage > 8.4 {         return true     } else {         return false ...

Treehouse Intermediate Course - Part 10 (Closures 1)

Image
Yes! So completes the aim to get four consecutive days! I actually enjoyed generics more than I thought - the concepts were so difficult but it was interesting finding out about them. Now onto closures - the area of Swift that I find hardest of all! This is apparently a 146 minute course, so I'll likely need at least 5 or 6 entries for this. 24 separate steps, so yes - similar to generics in terms of length! After that, the other iOS intermediate track (there is some crossover there with the Swift one), has a few other projects and bits. So that will be next! OK, let's go! Start Time - 12:22 Functions as Data A key point already is that closures are not a type. It is more that they are 'anonymous functions'. Simple functions - a recap! func printString( _ string: String ) {     print ( "Printing the string passed in: \ ( string )" ) } printString ( "Jeff" ) We can create a constant/variable and assign a function to it. No ar...