Posts

Showing posts with the label type alias

Ray Wenderlich Functions and Types Course - Part 3

Image
Here we go! Getting back into a routine with this! Straight on to continue closures... Start Time - 19:45 Closure Syntax Writing closures inline is one of the main benefits. Using shorter syntax can make them easier but can also make it more complicated to figure out... This old chestnut I've seen before. let longClosure = { (a: Int , b: Int ) -> Int in     return a * b      } longClosure ( 4 , 3 ) let noParameterTypes = { (a, b) -> Int in     a * b      } let noReturnTypes : Operate = { (a, b) in     a * b } let shortClosure : Operate = { $0 * $1 } noParameterTypes ( 4 , 3 ) noReturnTypes ( 4 , 3 ) shortClosure ( 4 , 3 ) The difference is that there was a type alias with the closure signature there.  Here is a point about trailing closures -  // -------------------------------------- func printResult ( _ a: Int , _ b: Int , _...

Lynda Course - Swift 5 Essential Thinking (Part 5)

Image
Right! Back on it after several days away. Still struggling to get into some sort of routine. So I'm glad that I've managed to create a little bit of time now - around 40 minutes. Need to go over some of the last bit on closures before the next section... Start Time - 17:14 Type Aliasing OK, it was this bit to go over! typealias AttackTuple = (name: String , damage: Int , rechargeable: Bool ) var sunStriker: AttackTuple = ( "Bruce" , 4 , true ) I totally get the benefits of type alias. There is no initial value given to the AttackTuple. But the var of sunStriker does.  func levelUpAttack(baseAttack: AttackTuple ) -> AttackTuple {     let increasedAttack: AttackTuple = (baseAttack.name, baseAttack.damage + 10 , true )          return increasedAttack      } levelUpAttack (baseAttack: sunStriker ) An example of how to use the AttackTuple as a type within a function....

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 18 (Build Interactive Story App Project 2)

Image
Back in Dubai and back to the code! I knew yesterday would be a right off. But just to clarify, I do NOT need to code every day. I reckon that 3-4 times a week for 30 minutes to 1 hour. That may not hit the self-imposed three hours a week target. Realistically, however, with school about to start again, I cannot guarantee three hours a week. I need to put together my long term plan for coding, which I will actually do below. I need more vision and purpose for it. Having faced several setbacks with it, I can't let that deter me. These may seem like random, unconnected thoughts but they do actually link together. So, before continuing with Treehouse, let's map out my long term plan! Step 1(June 2018-December 2018) - learn the basics syntax and principles of coding with Swift. Step 2 (January 2019 - June 2019) - learn more intermediate level coding and create several of my own projects. Step 3 (July 2019 to December 2019) - build on the intermediate concepts, learn some more...