Posts

Showing posts with the label Swift

RW.com: Storyboards Article - Part 2

Image
Here we go! Part 2 - and final bit of this article!  Start Time - 15:04 Before we got to 'Building the Add Player Scenes'. Aim is to basically complete this app project, then have a think about how I could adapt it for something of my own. Scratch that - ACTUALLY adapt it for something of my own. Add button put in - bar button item with the settings changed. Then a new NC, with the segue put in. All fine! iOS 13 - no code needed and easier to put the segue in. Nice! Lots of bits and pieces with the settings - static for the content etc. etc. Segue bit is all logical; TVC will provide a back button automatically, if there is a segue put in to another Controller. The swiping gesture bit doesn't quite work for the right one for some reason...let's just see if I need to connect something there... Stopped at 16:05 (approx 45 minutes so far - with interruptions) Continued at 16:25 So a few glitches with this project - some with the segue for swipe gesture ...

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

Treehouse Intermediate Course - Part 11 (Closures 2)

Image
So, as expected, I had to miss two days. But I'm back! I have a bit of time this evening to carry on with closures - certainly, completing the first part of the Treehouse track. So far, it's all been fine and I haven't found any issues. OK, let's go! Start Time - 18:56 func gameCounter() -> IntegerFunction {          var localCounter = 0          func increment( _ i: Int ) {         print ( "Integer passed in: \ ( i )" )     }          return increment } So just a reminder of scope. The localCounter variable is local as it is inside the body of the method; it can't be used outside that function.  *Paused at 19:03 (not able to concentrate - need to come back to this to take it in properly.) *Continued at 20:11 The increment function now has localCounter += inside it. It can use the localCounter var as it is defi...

Treehouse Intermediate Course - Part 5 (Generics 3)

Image
So to save the strain on my eyes, I am going to do several shorter entries today but put them into this one blog. It seems silly to have shorter entries which are all about the same content! Last time, generics was tough. But it was useful stuff! The challenge was tricky and so was the content; I'm going to continue with the current course, then do extra reading wherever necessary. Start Time - 09:55 Class Based Type Constraints So Pasan states that the example is 'trivial'...doesn't bode well! class Shape {}          func centre<T: Shape >(of shape: T ) {      print ( "Called" )     } let testShape = Shape () centre (of: testShape ) So just an example here of creating a class and then declaring the type within the <T: Shape> bit.  It works with inheritance too - if I created a  subclass of Shape it would work.  func centreOf( _ shape: Shape ) {     print...

Treehouse Intermediate Course - Part 4 (Generics 2)

Image
The run continues! Though just a short-ish entry today as I only have around half an hour. More time tomorrow, then nothing for Friday through to Sunday! But the main thing is I have momentum! Let's crack on with generics! Start Time - 10:08 Code challenge - Wow this looks hard! Let's try breaking it down... OK, so we have a [T] type and the transformation of (T) -> U - these need to be in the parameters. The return is type U. The return is then a square function. Let's try some things out! Opening a playground! func map<T, U>(array: [ T ], transformation: ( T ) -> U ) -> U {      } That seems to make sense so far! For the next bit though....just gonna check back the previous video as the transformation part has flummoxed me! Ah ok, I think I'm on to something. I need to do a separate function for the square, then put that into the transformation bit.... func map<T, U>(array: [ T ], transformation: ( T ) -> U...

Treehouse Intermediate Course - Part 3 (Generics 1)

Image
Yes the momentum continues! Today the aim is to cover half of the Generics bits. I know a bit about these but can't think much else other than downcasting/upcasting. There'll be more for sure! Also, I am going to ensure to do the extra reading parts, where relevant, as well as any coding practice.  Start Time - 15:04 Writing Repetitive Code So generics presumably means using the 'any' type and avoid using repetitive code. So I was right in that sense! Also, this links to the F1 quiz I've done before, which is in dire need of other options. Need to have sections for drivers, teams or difficulty level...I had to give up on that project back in January. Back to the course! Loops for example are an elegant construct - much better than typing out verbose code! func swapInts( _ a: Int , b: Int ) {     var tempA = a     a = b     b = tempA                } swapInts ( 4 , b: 7 ) ...