Posts

Showing posts from July, 2019

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

Treehouse Intermediate Course - Part 2 (API Design Guidelines 2)

Image
So, feeling still buoyed by my fresh new Treehouse approach, I'm getting another entry done - two in a day baby! Some before and some after dinner. I actually went a little further than I thought I did earlier, so that's good. Start Time - 18:05 Prepositional vs Grammatical Phrases Well the advantage here is that I'm a native English speaker. Now we're focusing on the English language! Not only am I native but I actually love grammar. The rules, the exceptions...part of the reason why Swift is perfect for me! Prepositions - where something is. Or when something happened (technically that's more of a conjunction). Function move. I assume we need moveTo. Yes - moveTo for the function name. Or have to as the argument label. Yes the below makes more sense. In another example, you need to put the preposition into the function name - if there are two argument labels, this is an exception to the rule. Extra Reading So straight from this website  - htt...

Treehouse Intermediate Course - Part 1 (API Design Guidelines 1)

Image
sSo begins the recommencement of Treehouse! Yes, it's been a long time and I was certainly put off it before. This time, though, I have got a good grounding from such a range of courses, including practical projects along the way. So I'm going to do something else that's new - supplement my learning with other stuff! In each entry, I will include further reading and - where applicable - code practice! Rather than race through to get it done quickly, I'm changing my approach. Let's say that the focus is on optionals, then I will go through the content, then look at other bits on optionals - online, in Swift book etc. etc., then include some practice on playground... you get the drill! So, I'm excited for this and, as I've said, this will be more about going deeper and getting to grips with the content each time rather than racing through. OK, let's do this!! Start Time - 09:30 Rather than I just continue, I'm going back to the start of this sect...

Stephen DeStefano Swift 5 Course - Part 10 (Lectures 55 to 58 - STOPPED!)

Image
So I've managed to leave it nearly a week! Couldn't be helped as the weekend was so busy and just didn't get the chance Tuesday or yesterday. Anyway, I've got onto the good stuff...the projects! I hope these live up to the hype I've created in my head for them. Once I've got the first couple of these done, I am going to seriously look at the best way forward, coding-wise. It could be Treehouse! Right, let's get started.. Start Time - 10:21 Brain Training! This sounds like fun! Sprite Kit is going to be used - I've had very little experience with that so that could be useful. Here's how it looks - ML - not sure what this stands for yet! Right, it's Machine Learning. My Xcode is still updating - so I can't follow along just yet. So we are 'training a model'. It could be something like distinguishing between cats and dogs. In this case it is distinguishing between numbers! So the handwritten element to this sounds cool. Pr...

Stephen DeStefano Swift 5 Course - Part 9 (Lectures 39 to 54)

Image
Here's me maximising time! I'm getting on a train in little under two hours. So a perfect time to code! I've actually packed everything, apart from what one needs post shower! So time to get the 'what's new in Swift' bits done. Then it can be the practical, project-based part! That's where I tend to REALLY learn! So let's get these bits done today.  Start Time - 07:44 New in Swift 4.1 Equatable protocol - allows you to compare an instance of a type against another. Not sure what all that means to be honest! Hashable - again, something that Swift can now do that used to be quite verbose code. Key decoding strategy for codable - something about going from snake case to camel case... Conditional conformance - now able to make easier comparisons. Possible to add protocol conformance to a type, as long as it satisfies the condition. It's supposed to make it all safer - the compiler won't build whereas before it would crash... Recursive ...

Stephen DeStefano Swift 5 Course - Part 8 (Lectures 32 to 38)

Image
Yes, two in a day! As mentioned earlier, I want to crack on and get the technical stuff DONE! Just want to get on to the projects. So the plan is to get at least collections done, then hopefully enumerations (maybe error handling too!) Start Time - 20:08 Arrays Again, as with other stuff in this course, I know this well so more of a skim through. A couple of cool things. The default value part is the same item repeated basically. The adding two arrays together means a bigger list basically. Can use the isEmpty property. Then use that within an if statement. Other stuff insert at, append, remove all etc. So using the range ... to put in several values at once. Iterating over the array. Use of the if let to see if an item is in the array. Use of sorted function. Then 'by'; you can use the < or >. Or others probably! Quiz - 10 out of 10 and one of the easiest so far! Dictionaries The syntax and concept of these is absolutely fine. Key-value pairs...

Stephen DeStefano Swift 5 Course - Part 7 (Lectures 26 to 31)

Image
So continuing with Control Flow! Going to do approximately an hour now - so that will be the rest of this chapter, then the next one on Strings.  Start Time - 13:20 If/else Just a catch up on this - skimming through! Simple example above. The use of else if as the alternative cases. Nested if statements - having an if statement with one that follows immediately. Simple. Switch Statements Again, I'm happy with this. Has to be exhaustive, is better for situations with numbers. Using several values for different cases - And this is with number ranges - Tuples with switch statements - Again, straightforward stuff. You just need to do the case with two values (as there are two - cars and weeks). In the above, there are closed values, the wildcard bit (underscore used). You can also use value binding by creating a value within the case  - So you then use those temp values that have been binned within the print statements. Where clause - can be u...

Stephen DeStefano Swift 5 Course - Part 6 (Lectures 23 to 25)

Image
Yes cracking on! Got a bit of time this morning before heading to my Uncle's and Auntie's. I want to cover Optionals then Control Flow. All very doable! Let's go! Start Time - 08:19 Optionals So I know about these but good to go over! They're used in situations where they may not be a value stored. Nil means the absence of a valid object. You can do these for any type at all. Optional types are returned where there may not have been a value e.g. when converting from string number to actual int number. The question mark syntax. Good way of understanding this is that the ? QUESTIONS whether something may not have a value. So the question bit is key there! You can only use nil with optionals. Optionals can only be var as the values are likely to change. If you create an optional without an initial value then it automatically sets this to nil. Forced unwrapping Comparing the optional against nil.... That's not forced unwrapping - that's just ch...