After yesterday’s Mac-sized stumbling block, it’s back to the lesson.
Yesterday (and this morning) I learned … Optionals.
Optionals are a way to allow an element to hold a nil
value, or where the value is absent. An “optional” is a wrapper around an element that exists in one of two states. Either the element has a value, or it doesn’t. If it doesn’t, then it’s nil
. If it does, then the element can be “unwrapped” so that its value can be accessed/used.
I’m used to testing for null
in my PHP scripts, and there wasn’t any need for something like an “optional”, but I can kind of see where this would be useful.
Optionals then get a bit murky with concepts such as ‘forced unwrapped’ (!) and ‘optional binding’. Whole lot of stuff to take in for one lesson, but I hope enough of it sinks it for me to remember the concepts when I need them.
Today I learned … Dictionaries.
Using the loosest definition of the word ‘dictionary’, a ‘Dictionary’ collection type is an array with a key/value pair. Otherwise knows as … an ‘array’ to those of us who have been using such things in other languages like PHP. So, I guess I knew what this was by virtue of having used it previously, only I didn’t know it had a special name.
That’s why I’m here to learn. They may all be coding languages, but they’re not all the same coding languages.