Stephen DeStefano Swift 5 Course - Part 9 (Lectures 39 to 54)
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 constraints on associative types - what a mouthful! So using a protocol within itself...

I think the idea is that you can have properties matching the behaviour of the class? Not sure again!

OK so you can have associated types of other custom classes if they are linked. Hmmm still very unclear!
Build configuration import testing - something about simplifying the testing process....
Target environment testing - something about using actual device rather than simulator.
Flat map now compact Map - transforming items in a collection. So if in a collection you have mixed types of items, the compactMap method ensures that you get rid of the type you don't want.
Swift 4.2
Of course there will be more updates with Swift 5, which Stephen does not cover on this course! So how useful these updates are as they are now a little older...anyway, still worth doing!
Derived collections of enum cases - using caseIterable protocol.
Warning and error diagnostic directives - #warning and #error. Stephen calls them 'pound' but he means hashtag. You can put in these within the code.
Dynamic member lookup - So you can use a subscript method. This is all very advanced and confusing!
Enhanced conditional conformances - a link back to the purchasable example.
Random number generation and shuffling- ooh! So for random number generation is much simpler, which I have actually already used. No need to use arc4random. It is now native - built into Swift. Much simpler! Before you had to convert between different types of Int and the Swift Int... yes this was a good idea!
Shuffle method - this is cool! so use of keyword 'shuffled' means that one element is returned randomly. This is actually better than the whole random number generator, then put into the array index. Cool! Something useful!
Simpler more secure hashing - you can generate these hash values (unique identifier nos.) more easily. Guaranteed to have different hash number.
Checking sequence elements... - allSatisfy method - checks if all items in a sequence (actually, a number array in the example) pass a condition. Cool!
In place collection removal - so objects get removed that match that condition. So you need to use removeAll then a closure with what is needed to be removed.
Boolean tagging - use of .toggle method to flip between true and false. Easily done rather than lines of code.
Finish Time - 08:19 (35 minutes total)
So that's all the new features! Mostly a waste of time, to be perfectly honest. But I have got several useful takeaways - the shuffle method, checking elements in array, removing elements, boolean tagging - most of the stuff towards the end! Especially the shuffle method - before I would be having a random number generator, then the index put in with that number...will be interesting to try that out in the next relevant project! So next time code will be realistically Monday. That's a few days away but I've certainly done well in the last three entries to finish off Stephen's confusing but useful at times technical bits. Next time, first of the projects!
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 constraints on associative types - what a mouthful! So using a protocol within itself...

I think the idea is that you can have properties matching the behaviour of the class? Not sure again!

OK so you can have associated types of other custom classes if they are linked. Hmmm still very unclear!
Build configuration import testing - something about simplifying the testing process....
Target environment testing - something about using actual device rather than simulator.
Flat map now compact Map - transforming items in a collection. So if in a collection you have mixed types of items, the compactMap method ensures that you get rid of the type you don't want.
Swift 4.2
Of course there will be more updates with Swift 5, which Stephen does not cover on this course! So how useful these updates are as they are now a little older...anyway, still worth doing!
Derived collections of enum cases - using caseIterable protocol.
Warning and error diagnostic directives - #warning and #error. Stephen calls them 'pound' but he means hashtag. You can put in these within the code.
Dynamic member lookup - So you can use a subscript method. This is all very advanced and confusing!
Enhanced conditional conformances - a link back to the purchasable example.
Random number generation and shuffling- ooh! So for random number generation is much simpler, which I have actually already used. No need to use arc4random. It is now native - built into Swift. Much simpler! Before you had to convert between different types of Int and the Swift Int... yes this was a good idea!
Shuffle method - this is cool! so use of keyword 'shuffled' means that one element is returned randomly. This is actually better than the whole random number generator, then put into the array index. Cool! Something useful!
Simpler more secure hashing - you can generate these hash values (unique identifier nos.) more easily. Guaranteed to have different hash number.
Checking sequence elements... - allSatisfy method - checks if all items in a sequence (actually, a number array in the example) pass a condition. Cool!
In place collection removal - so objects get removed that match that condition. So you need to use removeAll then a closure with what is needed to be removed.
Boolean tagging - use of .toggle method to flip between true and false. Easily done rather than lines of code.
Finish Time - 08:19 (35 minutes total)
So that's all the new features! Mostly a waste of time, to be perfectly honest. But I have got several useful takeaways - the shuffle method, checking elements in array, removing elements, boolean tagging - most of the stuff towards the end! Especially the shuffle method - before I would be having a random number generator, then the index put in with that number...will be interesting to try that out in the next relevant project! So next time code will be realistically Monday. That's a few days away but I've certainly done well in the last three entries to finish off Stephen's confusing but useful at times technical bits. Next time, first of the projects!
Comments
Post a Comment